-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchpasswd.php
More file actions
93 lines (72 loc) · 2.69 KB
/
chpasswd.php
File metadata and controls
93 lines (72 loc) · 2.69 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
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
<?php
/*
This file is part of Scorecard, Copyright 2013-2014 Dan Robinson, Nancy Wallace and John Holland.
Scorecard is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Scorecard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Scorecard. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<?php
session_start();
$page_name="chpasswd.php";
$page_title = "Voter Scorecard Change Password Action";
?>
<?php include 'header.php'; // need this for db connection ?>
<?php $submitted_username = '';
if(!empty($_POST))
{
// echo $_POST['username'] . "<br>";
// echo $_POST['oldpassword'] . "<br>";
// echo $_POST['newpassword1'] . "<br>";
// echo $_POST['newpassword2'] . "<br>";
// This query retrieves the user's information from the database using
// their username.
$query = "
SELECT
id,
username,
password
FROM users
WHERE
username = '" . $_POST['username'] . "'";
// echo $query;
// Execute the query against the database
$sql_query = mysqli_query($link, $query);
$row = mysqli_fetch_assoc($sql_query);
$login_ok = false;
$check_password = hash('sha256', $_POST['oldpassword'] );
if($check_password === $row['password'])
{
$login_ok = true;
}
if($login_ok)
{
if ($_POST['newpassword1'] === $_POST['newpassword2']) {
// passwords match and new password checks out
$query = " UPDATE users set " .
"password='" . hash('sha256', $_POST['newpassword1']) . "'" .
"WHERE username = '" . $_POST['username'] . "'";
// Execute the query against the database
$sql_query = mysqli_query($link, $query);
echo "<table class=\"bottomtablenowidth\"><tr><td><h3>password changed.</h3></td></tr></table>";
}
else
{ print "<span style=\"align:center;\"><h3>passwords don't match!!</h3></span>";
}
}
else
{
// Tell the user they failed
print("Login Failed.");
if(isset($_SESSION['user']))
unset($_SESSION['user']);
}
}
?>