Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
KotsiosDimis committed Dec 27, 2024
1 parent 85ee2fa commit feb7e6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions blokus.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
$router->add('POST', 'users/logout', 'logoutUser'); // POST /users/logout -> logoutUser function
$router->add('GET', 'users/session', 'checkSession'); // GET /users/session -> checkSession function



//lobby functions
$router->add('GET', 'lobbys', 'getLobbies');

Expand Down
11 changes: 7 additions & 4 deletions lib/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
function registerUser($username, $password) {
try {
$pdo = getDatabaseConnection();

// Hash the password securely using PHP's password_hash
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

$sql = "INSERT INTO users (username, password_hash) VALUES (:username, :password)";
// Call the stored procedure to create the user with the securely hashed password
$sql = "CALL CreateUser(:username, :password)";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':username' => $username,
':password' => $hashedPassword,
':password' => $hashedPassword, // Use the hashed password here
]);

echo json_encode(['success' => true, 'message' => 'User registered successfully']);
Expand All @@ -25,6 +28,7 @@ function registerUser($username, $password) {
}



// **Login Function (Authenticate User)**
function loginUser($username, $password) {
session_start();
Expand All @@ -40,7 +44,7 @@ function loginUser($username, $password) {

if ($user) {
// Verify the entered password with the stored hashed password
if (password_verify($password, $user['password'])) {
if (password_verify($password, $user['password_hash'])) {
// If login is successful, store the user details in session
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];
Expand All @@ -57,7 +61,6 @@ function loginUser($username, $password) {
}



// **Logout Function (Destroy User Session)**
function logoutUser() {
session_start();
Expand Down

0 comments on commit feb7e6b

Please sign in to comment.