Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions classes/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ public static function loadaccount($id = 0)

public static function Login($password, $username){
$account = database::getRow('account', ['username'], 's', [$username]);
if (!isset($account['password'])) {
return '<script>alert("Wrong username or password")</script>';
} elseif (password_verify($password, $account['password'])) {
if ($account['admin'] == 1) {
$_SESSION['admin'] = $account['id'];
if ($account['attempts'] < 3){
if (!isset($account['password'])) {
return '<script>alert("Wrong username or password")</script>';

} elseif (password_verify($password, $account['password'])) {
if ($account['admin'] == 1) {
$_SESSION['admin'] = $account['id'];
}
$_SESSION['access'] = $account['id'];
} else {
$attempts = $account['attempts'];
$attempts++;
database::update('account', $account['id'], ['attempts'], 's', [$attempts]);
return '<script>alert("Wrong username or password")</script>';
}
$_SESSION['access'] = $account['id'];
} else {
return '<script>alert("Wrong username or password")</script>';
return '<script>alert("Too many attempts, Contact a admin!")</script>';
}
}

Expand All @@ -51,6 +59,12 @@ public static function add($password, $username, $admin){
}

public static function update($id, $password, $username, $admin){
if ($_POST["password"] == "") {
$result = accounts::loadaccount($id);
$password = $result['password'];
}else {
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
}
database::update('account', $id, ['password', 'username', 'admin'], 'sss', [$password, $username, $admin]);
}

Expand Down
2 changes: 1 addition & 1 deletion remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/styles.css">
<script src="https://kit.fontawesome.com/65416f0144.js" crossorigin="anonymous"></script>
<title>remove</title>
<title>Remove</title>
</head>

<body>
Expand Down
12 changes: 3 additions & 9 deletions users.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
header('location: account');
}
if ($_POST and isset($_GET['edit'])) {
$result = accounts::loadaccount($_GET['edit']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
if ($_POST["password"] == "") {
$password = $result['password'];
};
accounts::update($_GET["edit"], $password, $_POST["username"], $_POST["admin"]);
$return = accounts::update($_GET['edit'], $_POST['password'], $_POST['username'], $_POST['admin']);
header('location: /users');

}
if ($_POST and $_GET['add'] == 'account') {
$return = accounts::add($_POST['password'], $_POST['username'], $_POST['admin']);
Expand All @@ -33,7 +29,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/styles.css">
<script src="https://kit.fontawesome.com/65416f0144.js" crossorigin="anonymous"></script>
<title>Account</title>
<title>Users</title>
</head>

<body>
Expand All @@ -49,7 +45,6 @@
<i class="fa-solid fa-plus"></i>
</a>


<nav id="nav">
<ul>
<li><a href="/">Home</a></li>
Expand Down Expand Up @@ -83,7 +78,6 @@
<input type="submit" value="Versturen">
</form>';
} elseif (isset($_GET['add']) == 'account') {

echo '<div class="admin"><form method="post">
<label for="username">Username:</label>
<input type="text" name="username" required><br>
Expand Down