Skip to content

Commit

Permalink
Added token generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 26, 2023
1 parent a9c9119 commit 71d5a2f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Web/authentication/authenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@

namespace Vault\Authentication;

use mysql_xdevapi\Exception;
use Vault\Data\dataManager;

class authenticationManager {
public function Login(string $username, string $password) {
$data = new dataManager();
$data->getUserData($username);
if (session_status() == PHP_SESSION_ACTIVE) {
$data = new dataManager();
$user = $data->getUserData($username);
if (password_verify($password, $user->password)) {
$tm = new tokenManager();
$token = $tm->generateToken($user->uuid);
$_SESSION['uuid'] = $user->uuid;
$_SESSION['token'] = $token;
return true;
} else {
return false;
}
} else {
throw new Exception('No active session.');
}
}

public function Logout() {
if (session_status() == PHP_SESSION_ACTIVE) {
session_unset();
session_destroy();
return true;
} else {
throw new Exception('No active session.');
}
}
}

0 comments on commit 71d5a2f

Please sign in to comment.