-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
52 lines (45 loc) · 1.61 KB
/
signup.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
<?php
declare(strict_types=1);
session_start();
if (isset($_SESSION["username"])) {
header("Location: timeline.php");
}
if (isset($_POST["login"])) {
require("./config/config.php");
$mysql = new mysqli(MYSQL_IP, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE);
$retrieve = $mysql->prepare("SELECT * FROM tUser WHERE username=?");
$retrieve->bind_param("s", $_POST["username"]);
$retrieve->execute();
$result = $retrieve->get_result();
$username = $_POST["username"];
$password = $_POST["password"];
if ($result->num_rows === 0) {
$passwordHash = password_hash($password, PASSWORD_BCRYPT);
$insert = $mysql->prepare("INSERT INTO tUser(Username, Password) VALUES(?, ?)");
$insert->bind_param("ss", $username, $passwordHash);
$insert->execute();
createSession($username, $passwordHash);
header("Location: timeline.php");
} else {
echo "Account already exists!";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./assets/index.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Outfit">
<title>Nox | Login</title>
</head>
<body>
<ul id="navbar">
<li><p>SIMPLE. SAFE. SECURE.</p></li>
</ul>
<form id="login" action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" id="username" name="username" placeholder="USERNAME" required>
<input type="password" id="password" name="password" placeholder="PASSWORD" required>
<input type="submit" value="SIGNUP" id="submit" name="login">
</form>
</body>
</html>