-
Notifications
You must be signed in to change notification settings - Fork 5
/
recoverpass.php
203 lines (163 loc) · 6.42 KB
/
recoverpass.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
if(file_exists("functions.php")) include("functions.php"); else exit;
$username=$_GET['user'];
$authcode=$_GET['code'];
if(isset($_POST['password']))
{
global $mysql_hostname,$mysql_username,$mysql_password,$mysql_dbname;
// username and password sent from form
$username=$_POST['username'];
$authcode=$_POST['authcode'];
$password=$_POST['password'];
//echo "username ".$username." authcode ".$authcode." password ".$password;
//Filter out html entities to prevent XSS attacks
$username = htmlentities($username);
$password = htmlentities($password);
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$conn = mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($mysql_dbname);
$sql="SELECT * FROM users WHERE username='$username' and authcode='$authcode'";
$result=mysql_query($sql,$conn);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username table row must be 1 row
//echo "count".$count;
if($count==1)
{
$sha1pass = PwdHash($password);
$sql="UPDATE users SET password='$sha1pass' where username='$username'";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
mysql_close($conn);
echo "Password Updated Successfully !!";
die();
//authenticated user
}
else
{
mysql_close($conn);
echo "Wrong Username or Authentication code ";
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Recover Password</title>
<link href="assets/css/bootstrap-with-responsive-1200-only.css" rel="stylesheet" type="text/css" />
<link href="assets/css/compileone.css" rel="stylesheet" type="text/css" />
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<link href="assets/css/styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="logo/favicon.ico"/>
<style type="text/css">
.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;z-index:1030;margin-bottom:0;}
.navbar-inner{
background:#F4F4F4;
font-size:14px;
height:40px;
}
.navbar-inner > a:hover{color:#666;}
a:hover{
color:#08c;
}
</style>
</head>
<body>
<?php include 'header.php' ?>
<script type="text/javascript" src="assets/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/login-signup.js"></script>
<script type="text/javascript" src="assets/js/jquery_002.js"></script>
<script type="text/javascript" src="assets/js/jquery_003.js"></script>
<script type="text/javascript" src="assets/js/mailcheck.js"></script>
<script type="text/javascript" src="assets/js/application.js"></script>
<div class="container">
<div class="row">
<div class="span2" style="margin-top:70px;">
<img src="./login.png" alt="CompileOne" height=200 width=200 style="float:left;"/>
</div>
<div class="signup span8">
<h2>Password Update</h2>
<form id="signup-form" method="post" novalidate="novalidate">
<input id="user" type="hidden" value=<?php echo $username;?> />
<input id="code" type="hidden" value=<?php echo $authcode;?> />
<div class="control-group ">
<div class="controls">
<div class="input-prepend input-append">
<label class="control-label add-on" for="login-password">Password</label>
<input id="login-password" tabindex="2" name="password" required="" type="password">
<label class="checkbox add-on show-password" for="login-show-password-checkbox">
<input id="login-show-password-checkbox" class="show-password-checkbox novalidate" data-toggle="showpassword" data-target="#login-password" type="checkbox"> Show
</label>
</div>
</div>
</div>
<span id="response" style="font-weight:bold"></span>
<div class="control-group">
<div class="controls">
<button type="submit" tabindex="3" class="btn btn-large btn-primary transitional">UPDATE</button>
</div>
</div>
<div class="control-group">
<div class="controls text-center">
<div class="span"> New Account? </div><a href="register.php">Register here</a>.
</div>
</div>
</form>
</div>
</div><!--/ .signup -->
</div>
</div>
<script>
$("#signup-form").submit(function(){
$('#response').text("");
var username = $('#user').val();
var authcode = $('#code').val();
var password = $('#login-password').val();
$.post('recoverpass.php', {'username':username,'authcode':authcode,'password':password},function(dt){
if(dt == "Password Updated Successfully !!")
{
$('#response').css("color","green");
$('#response').text(dt);
}
else
{
$('#response').css("color","red");
$('#response').text(dt);
}
});
return false;
});
$("#drop-sign").click(function(){
var username = $('#username').val();
var password = $('#password').val();
var remember = $('#remember').is(':checked')
$.post('login.php', {'todo':'login','username':username,'password':password,'remember':remember},function(dt){
if(dt == "true")
{
window.location = "home.php";
}
else
{
window.location = "login.php";
}
});
return false;
});
</script>
<?php include 'footer.php' ?>
</body>
</html>