-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_password.php
More file actions
103 lines (75 loc) · 2.43 KB
/
test_password.php
File metadata and controls
103 lines (75 loc) · 2.43 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
93
94
95
96
97
98
99
100
101
102
103
<?php
session_start();
require 'config/database.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Log in confirmation</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1> Log in test page </h1>
<?php
// Called when post request is made
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Create query
$stmt = $conn->prepare("SELECT passwordhash FROM passwords WHERE username = :username");
$stmt->bindParam(':username', $username);
// insert a row
$username = htmlspecialchars(strip_tags($_POST['username']));
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_NUM);
try{
$passwordhash = $stmt->fetch();
$password = test_input($_POST["password"]);
if ($passwordhash == null){
$correctPassword = False;
}else{
$correctPassword = password_verify($password,$passwordhash[0]);
}
if ($correctPassword){
$stmt = $conn->prepare("SELECT fullname FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_NUM);
$fullname = $stmt->fetch();
echo "Welcome " . $fullname[0] . "<br>";
echo "Log in succesful";
} else {
echo "Wrong Password!<br>Log in not succesful";
}
} catch (PDOException $e){
echo "No user found <br>";
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr>
<td align="left">Username:</td>
<td align="left"><input type="text" name="username" /><br></td>
</tr>
<tr>
<td align="left">Password:</td>
<td align="left"><input type="password" name="password" /><br></td>
</tr>
</table>
<input type="submit">
</form>
</div>
<!-- Create entry in the database
<?php
?>
-->
</body>
</html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>