forked from mitchgre/gregsList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcierge.php
138 lines (110 loc) · 3.65 KB
/
concierge.php
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
<?php
/*
This file will manage guests according to username and passwords.
" What is a lobby boy? A lobby boy is completely invisible, yet always
in sight. A lobby boy remembers what people hate. A lobby boy
anticipates the client's needs before the needs are needed. A lobby
boy is, above all, discreet to a fault. Our guests know that their
deepest secrets, some of which are frankly rather unseemly, will go
with us to our graves."
- M. Gustave
*/
require_once 'engineer.php';
require_once 'existentialist.php';
/*
Give 'em an ocular pat down.
https://www.youtube.com/watch?v=1SUmugkTyU8
*/
function clearUser()
{
if ( isset($_POST['user']) && $_POST['user'] !== null && $_POST['user'] !== '' )
{
$username = $_POST['user']; // lookup userid from db
//echo "received Username: " . $username;
if ( isset($_POST['pass']) && $_POST['pass'] !== "" )
{
// if user/password exists, check it, otherwise add new user
if ( usernameExists($username) )
{
$userId = getUserId($username);
$pass = getPass($userId); // get pass from db
if ($_POST['pass'] === $pass) // successful clearance
{
return "user cleared.";
}
else
{
return "invalid combination.";
}
}
else
{
if ( addUser($username,$_POST['pass']) )
{
return "user cleared.";
}
else
{
return "error creating new user.";
}
}
}
else
{
return "password cannot be empty.";
}
}
else
{
return "username cannot be empty.";
}
}
function getUserId($username)
{
$query = "select id from users where name=\"$username\"";
$userId = reset(returnStuff($query));
return $userId;
}
function getPass($userId)
{
$query = "select pass.word from pass ";
$query .= "inner join users on users.id=pass.user ";
$query .= "where users.id=$userId";
$pass = reset(returnStuff($query));
return $pass;
}
function changeUsername($username)
{
;
}
function changePassword($username)
{
;
}
/*
$username is assumed to be verified not to exist before this function is called.
At time of writing, this function is only called from clearUser().
*/
function addUser($username,$password)
{
// insert into users
$query = "insert into `users` (`name`) values (\"$username\") ";
if ( preparedStatement($query) )
{
// get new user id
$userId = getUserId($username);
// hash password
// insert into pass
$query = "insert into `pass` (`user`, `word`) ";
$query .= "values (".$userId.",\"".$password."\")";
// return true or false
return booleanReturn($query);
}
else
{
// something went wrong
// delete user name from db?
return false;
}
}
?>