ASSIGNMENT 5 | SESSIONs + User Management ASSIGNMENT 5 | SESSIONS + USER MANAGEMENT PRAVIIN M | IS 667 | 71749 | ONLINE 1 We have discussed sessions in class. Now, it is time to put sessions to use....

1 answer below »
Please see the task in the Assignment 5 pdf file. Need to add php code. Optional question at the end is not required.


ASSIGNMENT 5 | SESSIONs + User Management ASSIGNMENT 5 | SESSIONS + USER MANAGEMENT PRAVIIN M | IS 667 | 71749 | ONLINE 1 We have discussed sessions in class. Now, it is time to put sessions to use. Do the following: • We already have a database (UserManager attached in assignment files) and we also have a table that manages users. These users come with a user id! • Create a table to hold roles, which will contain a column for userid and then the role they have been granted. (you will need to join the user and the roles tables for fetching the information during login) • You should have different roles for performing the following operations o Admin (role): Should be able to do everything on the application; which is, create, update, delete a record. o Record Manager: This role should be able to create, edit, delete and view the users that they have created. Let`s say there are two record managers, FrodoBaggins and Gollum. Frodo should be able to edit and delete the records Frodo has created. They should not be able to touch Gollum`s records. On the other hand. Admin (Gandalf) should be able to edit. Delete both Frodo’s and Gollum’s records. o General User: This user role will NOT be able to create, delete, edit records. They should only be able to see all the records in the system. – Marked with who created the records! • If you are feeling adventurous, you can create a page to reassign roles instead of hardcoding them in the database. Which means, and admin can make P1, P2 and other users of the system into admins or general users. In short be able to manage roles through a GUI. (This question is totally optional) Copy your functions (code) to a file along with screenshots of your output and what not and upload to blackboard.
Answered Same DayNov 28, 2021

Answer To: ASSIGNMENT 5 | SESSIONs + User Management ASSIGNMENT 5 | SESSIONS + USER MANAGEMENT PRAVIIN M | IS...

Sanghamitra answered on Dec 04 2021
147 Votes
UserManager/.DS_Store
UserManager/.git/COMMIT_EDITMSG
login changes
UserManager/.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "StudyAbroadFair"]
    url = https://[email protected]/Praviin/studyabroadfair.git
    fetch = +refs/heads/*:refs/remotes/StudyAbroadFair/*
UserManager/.git/FETCH_HEAD
3537037324109ce63bbc7bdcc530db6a40af68db    not-for-merge    branch 'development' of https://bitbucket.org/Praviin/studyabroadfair
3537037324109ce63bbc7bdcc530db6a40af68db    not-for-merge    branch 'master' of https://bitbucket.org/Praviin/studyabroadfair
e7f12d88bd3f03e0e7e878d9a641ce561b55ee4b    not-for-merge    branch 'rc-01-18-18.1' of https://bitbucket.org/Praviin/studyabroadfair
603bc66e81441c99aa21d24f34191db851dcf892    not-for-merge    branch 'rc-07-26-18.1' of https://bitbucket.org/Praviin/studyabroadfair
90366cfd6bd9f0d056675e32445eaa6ab91d7d9c    not-for-merge    branch 'rc-08-01-18.1' of https://bitbucket.org/Praviin/studyabroadfair
d89a1e54809139db7387657044630c77808b5ad4    not-for-merge    branch 'rc-08-02-18.1' of https://bitbucket.org/Praviin/studyabroadfair
fec4aa6538cdd8258254d6a8e8f8d28ccfcbfc8c    not-for-merge    branch 'rc-08-14-19.1' of https://bitbucket.org/Praviin/studyabroadfair
bc1874d7fd2315bf741cda22277bf4df4029b883    not-for-merge    branch 'rc-08-15-18.1' of https://bitbucket.org/Praviin/studyabroadfair
2391d244bfc4760d4a712b294dcfd3b0fb375d29    not-for-merge    branch 'rc-10-18-18.1' of https://bitbucket.org/Praviin/studyabroadfair
3537037324109ce63bbc7bdcc530db6a40af68db    not-for-merge    branch 'rc-12-19-19.1' of https://bitbucket.org/Praviin/studyabroadfair
UserManager/.git/HEAD
ref: refs/heads/master
UserManager/.git/index
UserManager/.git/logs/HEAD
0000000000000000000000000000000000000000 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1491237353 -0400    commit (initial): Updated Code + echo`d passwords for explanation
3f54ee97e3396b4d52b593f22f10313cf884ec0d 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1491237364 -0400    checkout: moving from master to development
3f54ee97e3396b4d52b593f22f10313cf884ec0d 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1509460350 -0400    checkout: moving from development to clean-up
3f54ee97e3396b4d52b593f22f10313cf884ec0d d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509462987 -0400    commit: Code cleanedup -- indented and also place header.php wherever necessary.
d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1509462991 -0400    checkout: moving from clean-up to development
3f54ee97e3396b4d52b593f22f10313cf884ec0d d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509462997 -0400    merge clean-up: Fast-forward
d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509465859 -0400    checkout: moving from development to clean-up
d9e1c5f0ac79a1dc9523c1f6cf7
30d707b7cc89d 74d9e7399d06c5e906992094cac7c9f34f2b32a3 Praviin M 1509720119 -0400    commit: added some stuff
74d9e7399d06c5e906992094cac7c9f34f2b32a3 d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509720123 -0400    checkout: moving from clean-up to development
d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d 74d9e7399d06c5e906992094cac7c9f34f2b32a3 Praviin M 1509720131 -0400    checkout: moving from development to clean-up
74d9e7399d06c5e906992094cac7c9f34f2b32a3 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1509720200 -0400    commit: database update
e67f1190c8d83ae1344ff10be5b9affbf22485f5 d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509720203 -0400    checkout: moving from clean-up to development
d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1509720208 -0400    merge clean-up: Fast-forward
e67f1190c8d83ae1344ff10be5b9affbf22485f5 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1553789223 -0400    reset: moving to HEAD
e67f1190c8d83ae1344ff10be5b9affbf22485f5 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1553789252 -0400    checkout: moving from development to CodeCleanUp
e67f1190c8d83ae1344ff10be5b9affbf22485f5 cd0b263932ba0dfbe2463653313c2429839ab340 Praviin M 1599055446 -0400    commit: code commit
cd0b263932ba0dfbe2463653313c2429839ab340 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1599055455 -0400    checkout: moving from CodeCleanUp to development
e67f1190c8d83ae1344ff10be5b9affbf22485f5 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1599055481 -0400    checkout: moving from development to class-demo
e67f1190c8d83ae1344ff10be5b9affbf22485f5 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1600960832 -0400    reset: moving to HEAD
e67f1190c8d83ae1344ff10be5b9affbf22485f5 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1600960939 -0400    checkout: moving from class-demo to dev_new
e67f1190c8d83ae1344ff10be5b9affbf22485f5 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961012 -0400    commit: devdelete
50b86c7fa215124f3245d5a39f51d675579f6168 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961023 -0400    checkout: moving from dev_new to master1
50b86c7fa215124f3245d5a39f51d675579f6168 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961114 -0400    checkout: moving from master1 to login
50b86c7fa215124f3245d5a39f51d675579f6168 68a62af1b407346924bd44f191acce7864f68e4d Praviin M 1600961256 -0400    commit: login page start
68a62af1b407346924bd44f191acce7864f68e4d 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961330 -0400    checkout: moving from login to master1
50b86c7fa215124f3245d5a39f51d675579f6168 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961391 -0400    checkout: moving from master1 to register
50b86c7fa215124f3245d5a39f51d675579f6168 34846b22f14b68d30f8f5ff072a00a28466c6c08 Praviin M 1600961486 -0400    commit: registtration page
34846b22f14b68d30f8f5ff072a00a28466c6c08 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961521 -0400    checkout: moving from register to master1
50b86c7fa215124f3245d5a39f51d675579f6168 68a62af1b407346924bd44f191acce7864f68e4d Praviin M 1600961536 -0400    checkout: moving from master1 to login
68a62af1b407346924bd44f191acce7864f68e4d e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a Praviin M 1600961572 -0400    commit: login changes
e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a 34846b22f14b68d30f8f5ff072a00a28466c6c08 Praviin M 1600961577 -0400    checkout: moving from login to register
34846b22f14b68d30f8f5ff072a00a28466c6c08 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961615 -0400    checkout: moving from register to master1
50b86c7fa215124f3245d5a39f51d675579f6168 e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a Praviin M 1600961621 -0400    merge login: Fast-forward
e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a d7f73808e596471f2602124d1862b33548bdb416 Praviin M 1600961630 -0400    merge register: Merge made by the 'recursive' strategy.
d7f73808e596471f2602124d1862b33548bdb416 d7f73808e596471f2602124d1862b33548bdb416 Praviin M 1603978215 -0400    reset: moving to HEAD
d7f73808e596471f2602124d1862b33548bdb416 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1603978226 -0400    checkout: moving from master1 to master
UserManager/.git/logs/refs/heads/class-demo
0000000000000000000000000000000000000000 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1599055481 -0400    branch: Created from development
UserManager/.git/logs/refs/heads/CodeCleanUp
0000000000000000000000000000000000000000 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1553789252 -0400    branch: Created from development
e67f1190c8d83ae1344ff10be5b9affbf22485f5 cd0b263932ba0dfbe2463653313c2429839ab340 Praviin M 1599055446 -0400    commit: code commit
UserManager/.git/logs/refs/heads/development
0000000000000000000000000000000000000000 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1491237364 -0400    branch: Created from master
3f54ee97e3396b4d52b593f22f10313cf884ec0d d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d Praviin M 1509462997 -0400    merge clean-up: Fast-forward
d9e1c5f0ac79a1dc9523c1f6cf730d707b7cc89d e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1509720208 -0400    merge clean-up: Fast-forward
UserManager/.git/logs/refs/heads/dev_new
0000000000000000000000000000000000000000 e67f1190c8d83ae1344ff10be5b9affbf22485f5 Praviin M 1600960939 -0400    branch: Created from class-demo
e67f1190c8d83ae1344ff10be5b9affbf22485f5 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961012 -0400    commit: devdelete
UserManager/.git/logs/refs/heads/login
0000000000000000000000000000000000000000 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961114 -0400    branch: Created from master1
50b86c7fa215124f3245d5a39f51d675579f6168 68a62af1b407346924bd44f191acce7864f68e4d Praviin M 1600961256 -0400    commit: login page start
68a62af1b407346924bd44f191acce7864f68e4d e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a Praviin M 1600961572 -0400    commit: login changes
UserManager/.git/logs/refs/heads/master
0000000000000000000000000000000000000000 3f54ee97e3396b4d52b593f22f10313cf884ec0d Praviin M 1491237353 -0400    commit (initial): Updated Code + echo`d passwords for explanation
UserManager/.git/logs/refs/heads/master1
0000000000000000000000000000000000000000 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961023 -0400    branch: Created from dev_new
50b86c7fa215124f3245d5a39f51d675579f6168 e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a Praviin M 1600961621 -0400    merge login: Fast-forward
e2d2f5c5b37ff3fd5d6d0b350de6e29449069d4a d7f73808e596471f2602124d1862b33548bdb416 Praviin M 1600961630 -0400    merge register: Merge made by the 'recursive' strategy.
UserManager/.git/logs/refs/heads/register
0000000000000000000000000000000000000000 50b86c7fa215124f3245d5a39f51d675579f6168 Praviin M 1600961391 -0400    branch: Created from master1
50b86c7fa215124f3245d5a39f51d675579f6168 34846b22f14b68d30f8f5ff072a00a28466c6c08 Praviin M 1600961486 -0400    commit: registtration page
UserManager/.git/logs/refs/remotes/StudyAbroadFair/development
0000000000000000000000000000000000000000 3537037324109ce63bbc7bdcc530db6a40af68db Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/master
0000000000000000000000000000000000000000 3537037324109ce63bbc7bdcc530db6a40af68db Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-01-18-18.1
0000000000000000000000000000000000000000 e7f12d88bd3f03e0e7e878d9a641ce561b55ee4b Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-07-26-18.1
0000000000000000000000000000000000000000 603bc66e81441c99aa21d24f34191db851dcf892 Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-08-01-18.1
0000000000000000000000000000000000000000 90366cfd6bd9f0d056675e32445eaa6ab91d7d9c Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-08-02-18.1
0000000000000000000000000000000000000000 d89a1e54809139db7387657044630c77808b5ad4 Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-08-14-19.1
0000000000000000000000000000000000000000 fec4aa6538cdd8258254d6a8e8f8d28ccfcbfc8c Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-08-15-18.1
0000000000000000000000000000000000000000 bc1874d7fd2315bf741cda22277bf4df4029b883 Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-10-18-18.1
0000000000000000000000000000000000000000 2391d244bfc4760d4a712b294dcfd3b0fb375d29 Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/logs/refs/remotes/StudyAbroadFair/rc-12-19-19.1
0000000000000000000000000000000000000000 3537037324109ce63bbc7bdcc530db6a40af68db Praviin M 1600968832 -0400    fetch StudyAbroadFair: storing head
UserManager/.git/objects/0d/a2a8f410bed23e349701adc7c8d33788ba237b
UserManager/.git/objects/0d/a2a8f410bed23e349701adc7c8d33788ba237b
blob 96�?>


LOGIN PAGE START


UserManager/.git/objects/1d/cdc65647d80acd7727bed68792b179d6263a8a
UserManager/.git/objects/1d/cdc65647d80acd7727bed68792b179d6263a8a
blob 3645�require_once("config.php");
//Prevent the user visiting the logged in page if he/she is already logged in
if (isUserLoggedIn()) {
header("Location: myaccount.php");
die();
}
print_r($_POST);
//Forms posted
if (!empty($_POST)) {
$errors = array();
$email = trim($_POST["email"]);
$username = trim($_POST["username"]);
$firstname = trim($_POST["firstname"]);
$lastname = trim($_POST["lastname"]);
$password = trim($_POST["password"]);
$confirm_pass = trim($_POST["passwordc"]);
if ($username == "") {
$errors[] = "enter valid username";
}
if ($firstname == "") {
$errors[] = "enter valid first name";
}
if ($lastname == "") {
$errors[] = "enter valid last name";
}
if ($password == "") {
$errors[] = "enter valid password";
}
if ($confirm_pass == "") {
$errors[] = "enter valid password";
}
if ($email == "") {
$errors[] = "enter valid email address";
}
if ($password == "" && $confirm_pass == "") {
$errors[] = "enter password";
} else if ($password != $confirm_pass) {
$errors[] = "password do not match";
}
//End data validation
if (count($errors) == 0) {
$user = createNewUser($username, $firstname, $lastname, $email, $password);
print_r($user);
if ($user <> 1) {
$errors[] = "registration error";
}
}
if (count($errors) == 0) {
$successes[] = "registration successful";
}
}
require_once("header.php");
?>



Register




































 











UserManager/.git/objects/20/654b60cc25cb583fe96ebd9a31b3f3fbea3a9f
UserManager/.git/objects/20/654b60cc25cb583fe96ebd9a31b3f3fbea3a9f
blob 43
REGISTER
UserManager/.git/objects/26/8ddeafc3e31ab75ac87f64579e15cd3c52d1eb
UserManager/.git/objects/26/8ddeafc3e31ab75ac87f64579e15cd3c52d1eb
blob 744�//error reporting and warning display.
error_reporting(E_ALL);
ini_set('display_errors', 'On');
if (!ini_get('date.timezone')) {
    date_default_timezone_set('GMT');
    date_default_timezone_set('US/Eastern');
}
require_once("db-settings.php"); //Require DB connection
require_once("functions.php"); // database and other functions are written in this file
require_once("class.user.php");
session_start();
//loggedInUser can be used globally if constructed
if(isset($_SESSION["ThisUser"]) && is_object($_SESSION["ThisUser"]))
{
    $loggedInUser = $_SESSION["ThisUser"];
}
echo "SESSION VARIABLES ";
echo "
";
print_r($_SESSION);
echo "
";
echo "LOGGED IN USER DETAILS";
echo "
";
print_r($loggedInUser);
echo "
";
?>
UserManager/.git/objects/27/417fc873112a5ea4c9cf9d62fa2ff9681043d7
UserManager/.git/objects/27/417fc873112a5ea4c9cf9d62fa2ff9681043d7
blob 1384�/*
Navicat MySQL Data Transfer
Source Server : SMTP
Source Server Type : MySQL
Source Server Version : 50622
Source Host : localhost
Source Database : UserManager
Target Server Type : MySQL
Target Server Version : 50622
File Encoding : utf-8
Date: 10/28/2015 10:50:11 AM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `UserDetails`
-- ----------------------------
DROP TABLE IF EXISTS `UserDetails`;
CREATE TABLE `UserDetails` (
`UserID` varchar(120) NOT NULL,
`UserName` varchar(150) NOT NULL,
`FirstName` varchar(150) DEFAULT NULL,
`LastName` varchar(150) DEFAULT NULL,
`Email` varchar(150) NOT NULL,
`Password` varchar(1000) DEFAULT NULL,
`MemberSince` varchar(255) DEFAULT NULL,
`Active` int(11) DEFAULT NULL,
PRIMARY KEY (`UserName`,`Email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of `UserDetails`
-- ----------------------------
BEGIN;
INSERT INTO `UserDetails` VALUES ('4frvct', 'JohnSmith', 'John', 'Smith', '[email protected]', '6f4e26455b0f9c987a0009f3c5bd12786300b90fa76fb5399c82f2e63ab7121aa', '1445987595', '1'), ('692g6q', 'PraviinM', 'Praviin', 'Mandhare', '[email protected]', '1e905117d466dc32016cb71e3cb798cea73a942f2221fcbda1b5dc8104c2565ee', '1445961643', '1');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
UserManager/.git/objects/29/ecc3beec0ef4312b82ecb5742fdff9021a6f50
UserManager/.git/objects/29/ecc3beec0ef4312b82ecb5742fdff9021a6f50
blob 342
";
?>
UserManager/.git/objects/34/846b22f14b68d30f8f5ff072a00a28466c6c08
UserManager/.git/objects/34/846b22f14b68d30f8f5ff072a00a28466c6c08
commit 223�tree 81dde3dfbea01b8ca81db05e5e167bd6871b0d89
parent 50b86c7fa215124f3245d5a39f51d675579f6168
author Praviin M 1600961486 -0400
committer Praviin M 1600961486 -0400
registtration page
UserManager/.git/objects/34/c0bfd3c8c5886a82d643f97b052df42d83e3eb
UserManager/.git/objects/34/c0bfd3c8c5886a82d643f97b052df42d83e3eb
blob 149�require_once("config.php");
//Log the user out
if (isUserLoggedIn()) {
destroySession("ThisUser");;
}
header("Location:index.php");
die();
UserManager/.git/objects/3e/03da8381705ce5a75f8d812f0242da87bf47e0
UserManager/.git/objects/3e/03da8381705ce5a75f8d812f0242da87bf47e0
UserManager/.git/objects/3f/54ee97e3396b4d52b593f22f10313cf884ec0d
UserManager/.git/objects/3f/54ee97e3396b4d52b593f22f10313cf884ec0d
commit 204�tree cb63b464a06eba77cf409d3b030b8800fe82bc87
author Praviin M 1491237353 -0400
committer Praviin M 1491237353 -0400
Updated Code + echo`d passwords for explanation
UserManager/.git/objects/40/3b3b4c7b66ebebfa437d0a70850a73e3f38458
UserManager/.git/objects/40/3b3b4c7b66ebebfa437d0a70850a73e3f38458
blob 5488�//$password = md5("Smith");
//echo $password."
";
//$code = md5(uniqid(rand(), TRUE));
//echo $code;
//Generate a unique code
/**
* @param string $length
* @return string
*/
function getUniqueCode($length = "")
{
$code = md5(uniqid(rand(), TRUE));
if ($length != "") {
return substr($code, 0, $length);
} else {
return $code;
}
}
//$plainText = getUniqueCode(15);
//echo $plainText;
/**
* @param $plainText
* @param null $salt
* @return string
*/
function generateHash($plainText, $salt = NULL)
{
echo "plain text =" . $plainText . "
";
if ($salt === NULL) {
$salt = substr(md5(uniqid(rand(), TRUE)), 0, 25);
echo "salt when salt is null : " . $salt . "
";
} else {
echo "salt before substr : " . $salt . "

";
$salt = substr($salt, 0, 25);
echo "just salt : " . $salt . "

";
}
echo "return salt : " . $salt . "
";
echo "return sha ( salt ) : " . sha1($salt) . "
";
echo "return sha ( plaintext ) : " . sha1($plainText) . "
";
echo "return sha ( satl + plaintext ) : " . sha1($salt . $plainText) . "
";
echo "return salt . sha1 ( salt + plaintext ) : " . $salt . sha1($salt . $plainText) . "
";
return $salt . sha1($salt . $plainText);
}
//echo $newpassword;
//$compare = generateHash($_POST['password'], $newpassword);
//echo $compare;
/**
* @param $username
* @param $firstname
* @param $lastname
* @param $email
* @param $password
* @return bool
*/
function createNewUser($username, $firstname, $lastname, $email, $password)
{
global $mysqli, $db_table_prefix;
//Generate A random userid
$character_array = array_merge(range(a, z), range(0, 9));
$rand_string = "";
for ($i = 0; $i < 6; $i++) {
$rand_string .= $character_array[rand(
0, (count($character_array) - 1)
)];
}
//$rand_string = getUniqueCode(14);
//echo $rand_string;
//echo $username;
//echo $firstname;
//echo $lastname;
//echo $email;
//echo $password;
$newpassword = generateHash($password);
echo $newpassword;
$stmt = $mysqli->prepare(
"INSERT INTO " . $db_table_prefix . "UserDetails (
        UserID,
        UserName,
        FirstName,
        LastName,
        Email,
        Password,
        MemberSince,
        Active
        )
        VALUES (
        '" . $rand_string . "',
        ?,
        ?,
        ?,
        ?,
        ?,
'" . time() . "',
1
        )"
);
$stmt->bind_param("sssss", $username, $firstname, $lastname, $email, $newpassword);
//print_r($stmt);
$result = $stmt->execute();
//print_r($result);
$stmt->close();
return $result;
}
//Retrieve complete user information by username
/**
* @param $username
* @return array
*/
function fetchUserDetails($username)
{
global $mysqli, $db_table_prefix;
$stmt = $mysqli->prepare("SELECT
        UserID,
        UserName,
        FirstName,
        LastName,
        Email,
        Password,
        MemberSince,
        Active
        FROM " . $db_table_prefix . "UserDetails
        WHERE
        UserName = ?
        LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($UserID, $UserName, $FirstName, $LastName, $Email, $Password, $MemberSince, $Active);
while ($stmt->fetch()) {
$row = array('UserID' => $UserID,
'UserName' => $UserName,
'FirstName' => $FirstName,
'LastName' => $LastName,
'Email' => $Email,
'Password' => $Password,
'MemberSince' => $MemberSince,
'Active' => $Active);
}
$stmt->close();
return ($row);
}
//Check if a user is logged in
/**
* @return bool
*/
function isUserLoggedIn()
{
global $loggedInUser, $mysqli, $db_table_prefix;
$stmt = $mysqli->prepare(
"SELECT
        UserID,
        Password
        FROM " . $db_table_prefix . "UserDetails
        WHERE
        UserID = ?
        AND
        Password = ?
        AND
        active = 1
        LIMIT 1");
$stmt->bind_param("ss", $loggedInUser->user_id, $loggedInUser->hash_pw);
$stmt->execute();
$stmt->store_result();
$num_returns = $stmt->num_rows;
$stmt->close();
if ($loggedInUser == NULL) {
return false;
} else {
if ($num_returns > 0) {
return true;
} else {
destroySession("ThisUser");
return false;
}
}
}
//Destroys a session as part of logout
/**
* @param $name
*/
function destroySession($name)
{
if (isset($_SESSION[$name])) {
$_SESSION[$name] = NULL;
unset($_SESSION[$name]);
}
}
//Retrieve complete user information of all users
/**
* @return array
*/
function fetchAllUsers()
{
global $mysqli, $db_table_prefix;
$stmt = $mysqli->prepare(
"SELECT
        UserID,
        UserName,
        FirstName,
        LastName,
        Email,
        Password,
        MemberSince,
        Active
        FROM " . $db_table_prefix . "UserDetails
        ");
$stmt->execute();
$stmt->bind_result(
$UserID,
$UserName,
$FirstName,
$LastName,
$Email,
$Password,
$MemberSince,
$Active
);
while ($stmt->fetch()) {
$row[] = array(
'UserID' => $UserID,
'UserName' => $UserName,
'FirstName' => $FirstName,
'LastName' => $LastName,
'Email' => $Email,
'Password' => $Password,
'MemberSince' => $MemberSince,
'Active' => $Active
);
}
$stmt->close();
return ($row);
}
UserManager/.git/objects/45/7936d783cd28021cf47438bcc6f3d5c8ab9b62
UserManager/.git/objects/45/7936d783cd28021cf47438bcc6f3d5c8ab9b62
blob 83
hello world
UserManager/.git/objects/4a/842ab86609e687f428c8fb2fe55cc0d628b59e
UserManager/.git/objects/4a/842ab86609e687f428c8fb2fe55cc0d628b59e
blob 5379�//$password = md5("Smith");
//echo $password."
";
//$code = md5(uniqid(rand(), TRUE));
//echo $code;
//Generate a unique code
/**
* @param string $length
* @return string
*/
function getUniqueCode($length = "")
{
$code = md5(uniqid(rand(), TRUE));
if ($length != "") {
return substr($code, 0, $length);
} else {
return $code;
}
}
//$plainText = getUniqueCode(15);
//echo $plainText;
/**
* @param $plainText
* @param null $salt
* @return string
*/
function generateHash($plainText, $salt = NULL)
{
echo "plain text =" . $plainText . "
";
if ($salt === NULL) {
$salt = substr(md5(uniqid(rand(), TRUE)), 0, 25);
echo "salt when salt is null : " . $salt . "
";
} else {
echo "salt before substr : " . $salt . "

";
$salt = substr($salt, 0, 25);
echo "just salt : " . $salt . "

";
}
echo "return salt : " . $salt . "
";
echo "return sha ( salt ) : " . sha1($salt) . "
";
echo "return sha ( plaintext ) : " . sha1($plainText) . "
";
echo "return sha ( satl + plaintext ) : " . sha1($salt . $plainText) . "
";
echo "return salt . sha1 ( salt + plaintext ) : " . $salt . sha1($salt . $plainText) . "
";
return $salt . sha1($salt . $plainText);
}
//echo $newpassword;
//$compare = generateHash($_POST['password'], $newpassword);
//echo $compare;
/**
* @param $username
* @param $firstname
* @param $lastname
* @param $email
* @param $password
* @return bool
*/
function createNewUser($username, $firstname, $lastname, $email, $password)
{
global $mysqli, $db_table_prefix;
//Generate A random userid
$character_array = array_merge(range(a, z), range(0, 9));
$rand_string = "";
for ($i = 0; $i < 6; $i++) {
$rand_string .= $character_array[rand(
0, (count($character_array) - 1)
)];
}
//$rand_string = getUniqueCode(14);
//echo $rand_string;
//echo $username;
//echo $firstname;
//echo $lastname;
//echo $email;
//echo $password;
$newpassword = generateHash($password);
echo $newpassword;
$stmt = $mysqli->prepare(
"INSERT INTO " . $db_table_prefix . "UserDetails (
        UserID,
        UserName,
        FirstName,
        LastName,
        Email,
        Password,
        MemberSince,
        Active
        )
        VALUES (
        '" . $rand_string . "',
        ?,
        ?,
        ?,
        ?,
        ?,
'" . time() . "',
1
        )"
);
$stmt->bind_param("sssss", $username, $firstname, $lastname, $email, $newpassword);
//print_r($stmt);
$result = $stmt->execute();
//print_r($result);
$stmt->close();
return $result;
}
//Retrieve complete user information by username
/**
* @param $username
* @return array
*/
function fetchUserDetails($username)
{
global $mysqli, $db_table_prefix;
$stmt = $mysqli->prepare("SELECT
        UserID,
        UserName,
        FirstName,
        LastName,
        Email,
        Password,
        MemberSince,
        Active
        FROM " . $db_table_prefix . "UserDetails
        WHERE
        UserName = ?
        LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($UserID, $UserName, $FirstName, $LastName, $Email, $Password, $MemberSince, $Active);
while ($stmt->fetch()) {
$row = array('UserID' => $UserID,
'UserName' =>...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here