Repository navigation
Expand file tree
/
Copy pathchange_pass.php
More file actions
43 lines (37 loc) · 1.51 KB
/
Copy pathchange_pass.php
File metadata and controls
43 lines (37 loc) · 1.51 KB
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
<?php
require_once 'app/init.php';
$view->pageTitle = 'Change Password';
$usersTable = new \dvds4u\UsersTable();
$user = $usersTable->fetchByPrimaryKey($_SESSION['user_id']);
if(isset($_POST)) {
if(isset($_POST['password'])) {
$entered = $_POST['password'];
$actual = $user->__get('pass');
if(password_verify($entered, $actual)) {
$view->verified = true;
} else {
$view->errorMessage = "That's not the correct password for this account!";
}
} else if(isset($_POST['new_pass'])) {
$newPass = $_POST['new_pass'];
$confPass = $_POST['conf_pass'];
$passLength = strlen($newPass);
if(isPassError($newPass, $confPass)) {
$view->errorMessage = 'You\'ve got something wrong! :';
if(passLengthInvalid($newPass)) { // Check size
$view->errors[] = "Your password must between 8 and 16 characters.";
}
if(fieldsDontMatch($newPass, $confPass)) { // Check confirmation
$view->errors[] = "Your passwords don't match.";
}
} else {
$usersTable->updatePassword($_SESSION['user_id'], $newPass);
$view->success = 'Your Password has been successfully updated.';
}
}
}
require_once 'views/change_pass.php';
function isPassError($orig, $confirm)
{
return passLengthInvalid($orig) || fieldsDontMatch($orig, $confirm);
}