-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgetpass.php
76 lines (61 loc) · 2.31 KB
/
forgetpass.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
<?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
@include 'config.php';
session_start();
if(isset($_POST['submit'])) {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$nic = mysqli_real_escape_string($conn, $_POST['nic']);
$newPass = md5($_POST['new_password']);
$confirmNewPass = md5($_POST['confirm_new_password']);
$select = "SELECT * FROM user_form WHERE email = '$email' AND nic = '$nic'";
$result = mysqli_query($conn, $select);
if(mysqli_num_rows($result) > 0) {
if ($newPass === $confirmNewPass) {
$update = "UPDATE user_form SET password = '$newPass' WHERE email = '$email' AND nic = '$nic'";
mysqli_query($conn, $update);
$_SESSION['reset_success'] = true;
header('location: login_form.php');
exit();
} else {
$error = 'Passwords do not match!';
}
} else {
$error = 'Invalid email or NIC!';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password Reset Form</title>
<link rel="stylesheet" href="css/style.css">
<script src="js/script.js"></script>
</head>
<body>
<div class="form-container">
<form action="" method="post">
<h3>Password Reset</h3>
<?php
if(isset($error)){
echo '<span class="error-msg">'.$error.'</span>';
};
?>
<?php
if(isset($_SESSION['reset_success']) && $_SESSION['reset_success'] === true){
echo '<span class="success-msg">Password reset successfully! Please log in with your new password.</span>';
unset($_SESSION['reset_success']);
};
?>
<input type="email" name="email" required placeholder="Enter your email">
<input type="text" name="nic" required placeholder="Enter your NIC">
<input type="password" name="new_password" required pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$" placeholder="Enter your new password">
<input type="password" name="confirm_new_password" required placeholder="Confirm your new password">
<input type="submit" name="submit" value="Reset Password" class="form-btn">
</form>
</div>
</body>
</html>