Skip to content

Commit

Permalink
Added logging in functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 31, 2023
1 parent 57e3f98 commit ddf5729
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Web/authentication/authenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ class authenticationManager
{
public function login(string $username, string $password)
{
if ($username == null || $password == null) {
return false;
}

if (session_status() == PHP_SESSION_ACTIVE) {
$data = new dataManager();
$user = $data->getUserData($username);

if ($user == null) {
return false;
}

if (password_verify($password, $user->passkey)) {
$tm = new tokenManager();
$token = $tm->generateToken($user->user);
Expand Down Expand Up @@ -44,6 +53,8 @@ public function authenticated()
$tm = new tokenManager();
if ($sm->authTokens() && $tm->validToken($_SESSION['token'], $_SESSION['user'])) {
return true;
} else {
return false;
}
}
}
27 changes: 27 additions & 0 deletions Web/event/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Vault\authentication\authenticationManager;
use Vault\data\dataManager;
use Vault\inputManager;

if (!isset($_POST['user']) || !isset($_POST['pass'])) {
header('Location: /');
exit;
}

$am = new authenticationManager();
$dm = new dataManager();
$im = new inputManager();

$user = $im->escapeString($_POST['user']);
$pass = $im->escapeString($_POST['pass']);

if ($user == null || $pass == null) {
header('Location: /');
exit;
}

$am->login($user, $pass);

header('Location: /');
exit;
8 changes: 7 additions & 1 deletion Web/view/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
Login to Vault.
<form action="/auth" method="post">
<label for="user">Username</label>
<input id="user" name="user">
<br>
<label for="pass">Password</label>
<input id="pass" name="pass" type="password">
<br>
<button type="submit">Login</button>
</form>
</body>
</html>

0 comments on commit ddf5729

Please sign in to comment.