This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeuserpassword.php
180 lines (136 loc) · 4.88 KB
/
changeuserpassword.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
include( 'config.inc.php' );
include( 'globals.inc.php' );
include( $config['includepath'].'adodb/adodb.inc.php' );
error_reporting("E_ALL");
global $db_db, $db_host, $db_prefix, $db_pwd, $db_user;
$db_driver = 'mysql';
// print_r($_REQUEST);
if (isset($_REQUEST['userid'])){
$userid = trim(urldecode($_REQUEST['userid']));
}
else
{
$userid = "";
}
if (isset($_REQUEST['changed'])){
$changed = intval(trim($_REQUEST['changed']));
}
else
{
$changed = 0;
}
?>
<html>
<head>
<title> DILPS Password Management</title>
<link rel="stylesheet" type="text/css" href="admin.css" />
</head>
<body>
<?php
$db = NewADOConnection("mysql");
$rs = $db->Connect( $db_host, $db_user, $db_pwd, $db_db);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
// $db->debug = true;
if (!$rs)
{
die("Error connecting to database - please check your configuration");
}
?>
<table border="1" cellpadding="10" cellspacing="1">
<tr>
<th>
UserID
</th>
<th>
Current Password
</th>
<th>
New Password
</th>
<th>
New Password (Confirm)
</th>
<th>
Action
</th>
</tr>
<?php
if ($changed >0)
{
if (empty($userid))
{
echo ("<tr>\n<td colspan='5'>Data unchanged - an empty UserID was passed</td>\n<tr>");
}
else
{
if (empty($_REQUEST['current']))
{
echo ("<tr>\n<td colspan='5'>Please enter your current password</td>\n<tr>");
}
else
{
// authenticate user
$sql = "SELECT userid FROM ".$db_prefix."user_passwd "
."WHERE userid=".$db->qstr($userid)
." AND passwd=".$db->qstr(md5(trim($_REQUEST['current'])));
$rs = $db->Execute($sql);
if ($rs === false || $rs->RecordCount() != 1)
{
echo ("<tr>\n<td colspan='5'>Authentication failed!</td>\n<tr>");
}
else
{
if (empty($_REQUEST['password']))
{
echo ("<tr>\n<td colspan='5'>You may not use empty passwords</td>\n<tr>");
}
else
{
$passwd = trim($_REQUEST['password']);
if (empty($_REQUEST['confirm']))
{
echo ("<tr>\n<td colspan='5'>Please confirm your password</td>\n<tr>");
}
else
{
$confirm = trim($_REQUEST['confirm']);
if ($passwd != $confirm)
{
echo ("<tr>\n<td colspan='5'>Password and confirmation did not match</td>\n<tr>");
}
else
{
$sql = "UPDATE ".$db_prefix."user_passwd SET "
."passwd=".$db->qstr(md5($passwd))
." WHERE userid=".$db->qstr($userid);
$rs = $db->Execute($sql);
if ($rs === false)
{
echo ("<tr>\n<td colspan='5'>Password unchanged - a database error occured while saving your data</td>\n<tr>");
}
else
{
echo ("<tr>\n<td colspan='5'>Password changed successfully (<a href='index.php'>go back to login</a>)</td>\n<tr>");
}
}
}
}
}
}
}
}
echo ("<tr>\n");
echo ("<form method='POST' action='".$_SERVER['PHP_SELF']."'>");
echo ("<td><input type='text' name='userid' value='".$userid."'></td>");
echo ("<td><input type='password' name='current'></td>");
echo ("<td><input type='password' name='password'></td>");
echo ("<td><input type='password' name='confirm'></td>");
echo ( "<td>"
."<input type='hidden' name='changed' value='1'>\n"
."<input type='submit' value='Save'>\n"
."<a href='index.php'><button type='button' value='Cancel'>Cancel</button></a>"
."</td>");
echo ("</form>");
?>
</table>