-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_psw (2).php
90 lines (77 loc) · 2.36 KB
/
reset_psw (2).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
<?php
include('config.php');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Rest-Password Form</title>
<link href="resest_password.css" rel="stylesheet" type="text/css">
</head>
<body>
<style>
body{
background: url("img/password.jpg");
}
</style>
<div id="form">
<h1>Reset Password</h1>
<hr class="style1">
<br> <form action="" method="POST" >
<div>
<label>User-name:</label><input type="password" name="username" placeholder="Email Id">
</div>
<!-- <div> -->
<!-- <br>
<label>New-Password:</label><input type="password" name="password" placeholder="Password"> -->
<!-- </div> -->
<br>
<button input type="submit" value="reset">Reset</buton>
</div>
</div>
</form>
</div>
</body>
</html>
<?php
$username = "";
if(isset($_POST["reset"])){
// include('config.php');
$psw = $_POST["password"];
// $token = $_SESSION['token'];
$username = $_POST['username'];
$hash = password_hash( $psw , PASSWORD_DEFAULT );
$sql = mysqli_query($conn, "SELECT * FROM register WHERE username='$username'");
$query = mysqli_num_rows($sql);
$fetch = mysqli_fetch_assoc($sql);
if($username){
$new_pass = $hash;
mysqli_query($conn, "UPDATE register SET password='$new_pass' WHERE username='$username' ");
?>
<script>
window.location.replace("login page.php");
alert("<?php echo "your password has been succesfully reset"?>");
</script>
<?php
}else{
?>
<script>
alert("<?php echo "Please try again"?>");
</script>
<?php
}
}
?>
<script>
const toggle = document.getElementById('togglePassword');
const password = document.getElementById('password');
toggle.addEventListener('click', function(){
if(password.type === "password"){
password.type = 'text';
}else{
password.type = 'password';
}
this.classList.toggle('bi-eye');
});
</script>