forked from aegomez2/alumni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
30 lines (24 loc) · 914 Bytes
/
register.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
<?php
require 'config/initialize.php';
mustBeGuest();
if (isset($_POST['authForm'])) {
$username = sanitizeString($_POST['username'], $connection);
$fullName = sanitizeString($_POST['fullName'], $connection);
$password = sanitizeString($_POST['password'], $connection);
if ($username == "" || $fullName == "" || $password == "" || !ctype_alnum($username)) {
header("location: register.php");
} else {
$user = queryDatabase("SELECT username FROM user WHERE username='$username'", $connection);
if ($user->num_rows) {
header("location: register.php");
} else {
// constString + newUserId + password
$newUserId = getLastId($connection)+1;
$password = generatePassword($newUserId, $password);
$password = password_hash($password, PASSWORD_BCRYPT);
registerUser($username, $fullName, $password, $connection);
header('Location: authenticate.php');
}
}
}
view('auth/register');