|
@@ -1,9 +1,33 @@
|
1
|
1
|
<?php
|
|
2
|
+require_once "sql.php";
|
|
3
|
+require_once "utils.php";
|
|
4
|
+
|
|
5
|
+function hash_password($password)
|
|
6
|
+{
|
|
7
|
+ return md5($password);
|
|
8
|
+}
|
|
9
|
+
|
2
|
10
|
function user_create()
|
3
|
11
|
{
|
|
12
|
+ $username = get_post("username");
|
|
13
|
+ $password = get_post("password");
|
|
14
|
+ if (strlen($username) < 3)
|
|
15
|
+ error(422, "Username too short");
|
|
16
|
+ if (database_exec("SELECT id FROM users WHERE `username` = :username",
|
|
17
|
+ array(":username" => $username))->fetch() !== false)
|
|
18
|
+ error(409, "Username already exists");
|
|
19
|
+ database_exec("INSERT INTO users (`username`, `password`) ".
|
|
20
|
+ "VALUES(:username, :password)", array(":username" => $username,
|
|
21
|
+ ":password" => hash_password($password)));
|
|
22
|
+ user_login($username);
|
4
|
23
|
}
|
5
|
24
|
|
6
|
|
-function user_login()
|
|
25
|
+function user_login($username = false )
|
7
|
26
|
{
|
|
27
|
+ if ($username === false)
|
|
28
|
+ {
|
|
29
|
+ $username = get_post("username");
|
|
30
|
+ $password = get_post("password");
|
|
31
|
+ }
|
8
|
32
|
}
|
9
|
33
|
?>
|