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/content.html | 20 ++++++++++++++++++- signin/signin.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100755 signin/signin.php (limited to 'signin') diff --git a/signin/content.html b/signin/content.html index 458ecfb..ac9eb13 100755 --- a/signin/content.html +++ b/signin/content.html @@ -16,4 +16,22 @@ along with this program. If not, see . --> -

WIP

+

Sign in to GNUfault.org

+
+

If you need any help, email me at <connor@gnufault.org>.

+
+ 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