-
Notifications
You must be signed in to change notification settings - Fork 4
/
forgot.php
87 lines (72 loc) · 2.02 KB
/
forgot.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
<?php
// php sessions
session_start();
// if already logged in, redirect to account page
if(isset($_SESSION['username'])) {
header('Location: http://bankofvert/account.php');
die();
}
// import db creds
include('dbcreds.php');
// connect to mysql
$handle = mysql_connect($hostname, $username, $password)
or die('mysql_connect() failed');
// connect to database
$db = mysql_select_db('bankofvert', $handle)
or die('mysql_select_db() failed');
// we set this variable for any user-facing messages
$message = '';
// check if login request
if(isset($_GET['username'])) {
// craft vulnerable query
$query = "SELECT * from users where username='" .$_GET['username']. "'";
// get result of query from mysql
$res = mysql_query($query);
// if $res is false, query failed
if(!$res) {
$message = 'Username not found';
}
else {
// retrieve result set
$row = mysql_fetch_assoc($res);
// if username is set, the query was successful
// show email sent message
if(isset($row['username'])) {
$message = 'An email containing a reset link was sent to the email address of this username.';
}
else {
$message = 'Username not found';
}
}
}
?>
<html>
<head>
<style>
body {
font-family: sans-serif;
font-size: 20;
}
.hdr {
color: #ea7125;
}
.message {
color: #ff0000;
}
</style>
<title>Bank of VERT</title>
</head>
<body>
<center>
<h1 class="hdr">Welcome to the Bank of VERT</h1>
<h3>Enter your username to receive the reset link</h3>
<div>
<form method="GET">
Username: <input type="text" name="username" size="120" value="<?php if(isset($_GET['username'])) {echo $_GET['username'];};?>"><br/><br/>
<input type="submit" value="Submit">
</form>
<span class="message"><?php echo $message; ?><span>
</div>
</center>
</body>
</html>