-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateUser.php
More file actions
188 lines (162 loc) · 5.22 KB
/
Copy pathvalidateUser.php
File metadata and controls
188 lines (162 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
// Set and declare session variables
session_start();
$configs = include 'assets/.config.php';
// Variables needed by multiple functions that are not declared outside of this page.
function isValidUser($userName, $password) {
$hash = getPasswordHash($userName);
$isValid = password_verify($password, $hash);
return $isValid;
}
function getPasswordHash($userName) {
$user = USERNAME;
$pass = PASSWORD;
try {
$pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$hash = "";
$resultSet = $pdo->query("SELECT Password FROM tasks_user WHERE UserName = '$userName'");
foreach($resultSet as $row)
{
$hash = $row['Password'];
}
} catch(PDOException $err) {
echo $err->getMessage();
}
return $hash;
}
function getUsersFirstName($userName){
$user = USERNAME;
$pass = PASSWORD;
try {
$pdo = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$firstName = "";
$resultSet = $pdo->query("SELECT FirstName FROM tasks_user WHERE UserName = '$userName'");
foreach($resultSet as $row)
{
$firstName = $row['FirstName'];
}
} catch(PDOException $err) {
echo $err->getMessage();
}
return $firstName;
}
function newUserFirstName($newFirstName) {
$checkFirstName;
if($newFirstName != ' ') {
if(strlen($newFirstName) >= 3) {
$checkFirstName = true;
$_SESSION['checkFirstName'] = $checkFirstName;
} else {
$checkFirstName = false;
$_SESSION['checkFirstName'] = $checkFirstName;
}
}
}
function newUserLastName($newLastName) {
$checkLastName;
if($newLastName != ' ') {
if(strlen($newLastName) >= 3) {
$checkLastName = true;
$_SESSION['checkLastName'] = $checkLastName;
} else {
$checkLastName = false;
$_SESSION['checkLastName'] = $checkLastName;
}
}
}
function newUserEmail($newEmail) {
$checkEmail;
if(filter_var($newEmail, FILTER_VALIDATE_EMAIL)) {
$checkEmail = true;
$_SESSION['checkEmail'] = $checkEmail;
} else {
$checkEmail = false;
$_SESSION['checkEmail'] = $checkEmail;
}
}
function newUserPhone($newPhone) {
$checkPhone;
if(preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $newPhone)) {
$checkPhone = true;
$_SESSION['checkPhone'] = $checkPhone;
} else {
$checkPhone = false;
$_SESSION['checkPhone'] = $checkPhone;
}
}
function newUser_Name($newUsername) {
$checkUsername;
if(strlen($newUsername) >= 6){
$checkUsername = true;
$_SESSION['checkUsername'] = $checkUsername;
} else {
$checkUsername = false;
$_SESSION['checkUsername'] = $checkUsername;
}
}
function confirmPassword($newPassword, $passwordConfirm) {
$passwordCheck;
if($newPassword != '' && strlen($newPassword) >= 6) {
if($newPassword == $passwordConfirm) {
$passwordCheck = true;
$_SESSION['passwordCheck'] = $passwordCheck;
}
} else {
$passwordCheck = false;
$_SESSION['passwordCheck'] = $passwordCheck;
}
}
function errorShow($checkFirstName, $checkLastName, $checkEmail, $checkPhone, $checkUsername, $passwordCheck) {
global $errorCheck;
$errorCheck = array();
if ($checkFirstName === false) {
$errorCheck[] = 'fnError';
}
if ($checkLastName === false) {
$errorCheck[] = 'lnError';
}
if ($checkEmail === false) {
$errorCheck[] = 'emError';
}
if ($checkPhone === false) {
$errorCheck[] = 'phError';
}
if ($checkUsername === false) {
$errorCheck[] = 'unError1';
}
if ($passwordCheck === false) {
$errorCheck[] = 'pwError';
}
return $errorCheck;
}
function addUser($newFirstName, $newLastName, $newEmail, $newPhone, $newUsername, $newPassword) {
global $pass;
global $connPass;
global $e1;
global $e2;
$password = $newPassword;
$hash = password_hash($password, PASSWORD_DEFAULT);
$user = USERNAME;
$pass = PASSWORD;
$db = DATABASE;
$host = HOST;
try {
$conn = new PDO("mysql:host=localhost;dbname=test", $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connPass = "Connect Successful";
} catch(PDOException $e1) {
$connPass = "Connection Failed";
}
$insert_statement = 'INSERT INTO tasks_user(UserEmail, UserCellPhone, UserName, Password, FirstName, LastName, JoinDate, ActiveUser) VALUES(:newEmail, :newPhone, :newUsername, :passHash, :newFirstName, :newLastName, :joinDate, :activeUser)';
$dateIn = date("Y-m-d H:i:s");
$insert_params = array(':newEmail' => $newEmail, ':newPhone' => $newPhone, ':newUsername' => $newUsername, ':passHash' => $hash, ':newFirstName' => $newFirstName, ':newLastName' => $newLastName, ':joinDate' => $dateIn, ':activeUser' => 0);
try {
$insert = $conn->prepare($insert_statement);
$insert->execute($insert_params);
$last_id = $conn->lastInsertId();
$pass = "Query has been executed.";
} catch(PDOException $e2) {
$pass = "Query failed.";
}
}
?>