-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangepassword.php
executable file
·106 lines (93 loc) · 4.31 KB
/
changepassword.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
require 'core/config.php';
include INCLUDES_PATH . 'header.php';
if (!$user->isLoggedIn()) {
Redirect::to('index');
}
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'current_password' => array(
'show' => 'A <b>Password atual</b>',
'required' => true
),
'new_password' => array (
'show' => 'A <b>Nova password</b>',
'required' => true,
'min' => 6
),
'password_again' => array (
'show' => 'A <b>Password de novo</b>',
'required' => true,
'matches' => 'new_password'
)
));
if ($validation->passed()) {
if ((Hash::make(Input::get('current_password'), $user->data()->user_salt)) !== $user->data()->user_password) {
$print_errors[1][0] = 'Password incorreta';
} else {
$salt = Hash::salt(32);
$user->update(array(
'user_password' => Hash::make(Input::get('new_password'), $salt),
'user_salt' => $salt
));
Session::flash('homes', 'Password foi atualizada');
Redirect::to('index');
}
} else {
$print_errors[] = $validation->errors();
}
}
}
?>
<div class="container">
<div class="row">
<div class="col-3"></div>
<div class="col-6">
<div class="row">
<nav aria-label="breadcrumb" role="navigation" class="mx-auto">
<ol class="breadcrumb backbread">
<li class="breadcrumb-item"><a href="<?php echo URL_PATH . 'index'; ?>">Início</a></li>
<li class="breadcrumb-item"><a href="<?php echo URL_PATH . 'panel'; ?>">Painel do Utilizador</a></li>
<li class="breadcrumb-item active" aria-current="page">Definições</li>
</ol>
</nav>
</div>
<h2 class="titles mx-auto text-center">Alterar a password</h2>
<hr>
<form action="" method="post">
<div class="form-group">
<label for="current_password">Password atual</label>
<input type="password" id="current_password" name="current_password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label for="new_password">Nova password</label>
<input type="password" id="new_password" name="new_password" class="form-control" placeholder="Nova Password">
</div>
<div class="form-group">
<label for="password_again">Nova password de novo</label>
<input type="password" id="password_again" name="password_again" class="form-control" placeholder="Nova Password de novo">
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<div class="row pt-3">
<input type="submit" class="uk-button uk-button-primary w-50 mx-auto" value="Alterar">
</div>
</form>
</div>
<div class="col-3 pt-5">
<?php
if (!empty($print_errors)) {
foreach ($print_errors as $print_values) {
foreach ($print_values as $value) {
echo '<div class="alert alert-danger" role="alert">'.$value.'</div>';
}
}
}
?>
</div>
</div>
</div>
<?php
include INCLUDES_PATH . 'footer.php';
?>