From 81c04315ee022a044c8d22ae7a9bbe065e21f2df Mon Sep 17 00:00:00 2001 From: Connor Thomson Date: Sun, 20 Sep 2026 18:59:16 -0700 Subject: Add signin --- signin/signin.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 signin/signin.php (limited to 'signin/signin.php') diff --git a/signin/signin.php b/signin/signin.php new file mode 100755 index 0000000..6e88336 --- /dev/null +++ b/signin/signin.php @@ -0,0 +1,57 @@ +. + */ + +define('ROOT', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/'); + +require_once ROOT . '/php/session.php'; +require_once ROOT . '/php/database.php'; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $username = $_POST['username']; + $password = $_POST['password']; + $remember = isset($_POST['remember']); + + try { + $sql = "SELECT id, username, password, verification_code FROM users WHERE username = :username"; + + $user = fetch_row($sql, ['username' => $username]); + } catch (\PDOException $e) { + echo "Error: " . $e->getMessage(); + exit; + } + + // The same message either way, so it does not say which usernames exist + if (!$user || !password_verify($password, $user['password'])) { + echo "Username or password is not correct!"; + exit; + } + + if ($user['verification_code'] != '0001') { + set_user_id((int)$user['id']); + + header("Location: /signup/verify"); + exit; + } + + sign_in((int)$user['id'], $user['username'], $remember); + + header("Location: /"); +} + +?> -- cgit v1.2.3