finished final project
Deploy CSIS 2440 / deploy (push) Canceled after 0s

This commit is contained in:
2025-05-05 21:53:39 -06:00
parent 5cd4571a92
commit 3f844e4e06
32 changed files with 1087 additions and 219 deletions
+12 -10
View File
@@ -1,12 +1,12 @@
<?php
if (isset($_POST['form_id'])) {
require_once '../vendor/autoload.php';
include_once '../vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->safeLoad();
require_once 'base.php';
require_once 'db.php';
include_once 'base.php';
include_once 'db.php';
switch ($_POST['form_id']) {
case 'create-account':
@@ -15,6 +15,9 @@ if (isset($_POST['form_id'])) {
echo json_encode($result);
}
break;
case 'login':
if (isset($_POST['username']) && isset($_POST['password']))
echo json_encode(login($_POST['username'], $_POST['password']));
}
}
@@ -30,29 +33,28 @@ function username_exists($username)
function login($username, $password)
{
$user = exec_stmt('SELECT id FROM user WHERE username = ? AND password = ?', 'ss', $username, $password)->fetch_assoc();
$user = exec_stmt('SELECT id, password FROM user WHERE username = ?', 's', $username)->fetch_assoc();
if (!isset($user['id']))
return false;
if (!password_verify($password, $user['password'])) {
return false;
}
$_SESSION['id'] = $user['id'];
return true;
}
function signup($username, $password, $verify_password)
{
echo 'test';
if (username_exists($username))
return false;
echo 'username=' . $username;
if ($password != $verify_password)
return false;
$user_id = exec_stmt('INSERT INTO user (username, password) VALUES (?, ?)', 'ss', $username, $password);
echo 'user_id=' . $user_id;
$user_id = exec_stmt('INSERT INTO user (username, password) VALUES (?, ?)', 'ss', $username, password_hash($password, PASSWORD_DEFAULT));
if (!isset($user_id))
return false;