-
Notifications
You must be signed in to change notification settings - Fork 0
/
resetpassword.php
62 lines (56 loc) · 1.59 KB
/
resetpassword.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once("include/main.php");
requireOpen();
requireLogin(false);
$errors = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if((!isset($_POST["old_password"]) || trim($_POST["old_password"]) === '') || (!isset($_POST["new_password"]) || trim($_POST["new_password"]) === '')) {
array_push($errors, "No value given");
}
if (strlen($_POST["new_password"]) < 8) {
array_push($errors, "Password too short!");
}
if (!preg_match("#[0-9]+#", $_POST["new_password"])) {
array_push($errors, "Password must include at least one number!");
}
if (!preg_match("#[a-zA-Z]+#", $_POST["new_password"])) {
array_push($errors, "Password must include at least one letter!");
}
if(empty($errors)) {
if(resetPassword($_SESSION["id"], $_POST['old_password'], $_POST['new_password'], $conn)) {
array_push($errors, "Password incorrect");
} else {
header("Location: /");
}
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<?php
include("include/meta.php");
?>
</head>
<body>
<div class="login">
<h1>Breyta aðgangsorði</h1>
<form method="POST" action="/resetpassword.php">
<input type="password" name="old_password" placeholder="Núverandi lykilorð"/>
<input type="password" name="new_password" placeholder="Nýtt lykilorð"/>
<input type="submit" name="submit" value="Breyta lykiorði"/>
</form>
<?php
foreach($errors as $message) {
?>
<div class="error-box">
<img src="/assets/icons/error-24px.svg"/>
<p><?php echo $message ?></p>
</div>
<?php
}
?>
</div>
</body>
</html>