-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reset_password.php
161 lines (140 loc) · 5.72 KB
/
Reset_password.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
<?php
session_start();
?>
<?php
// including database
include 'partials\_dbconnect.php';
// including database
$alerterror = false;
$alertsuccess = false;
if(isset($_GET['crmail']) ){
$email = $_GET['crmail'];
}
if(isset($_GET['grmail']) ){
$email = $_GET['grmail'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_GET['crmail'])) {
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$passwordvalid = false;
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
$specialChars = preg_match('@[^\w]@', $password);
if (!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) < 8) {
$passwordvalid = true;
}
$sql1 = "SELECT c_email FROM `customer` WHERE `c_email` = '$email' ";
$result1 = mysqli_query($conn, $sql1);
$num1 = mysqli_fetch_array($result1);
if ($num1 > 0) {
if ($password == $confirmpassword && $passwordvalid == false) {
$hashpassword = password_hash($password, PASSWORD_DEFAULT);
$sql2 = "UPDATE customer set c_password='$hashpassword' where c_email='$email'";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
$alertsuccess = "Password reset successfull!!";
}
} else {
$alerterror = "Password not match or Password should be at least 8 characters in length and should include at least one upper case letter, one number, and one special character.";
}
}
}
if (isset($_GET['grmail'])) {
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$passwordvalid = false;
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
$specialChars = preg_match('@[^\w]@', $password);
if (!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) < 8) {
$passwordvalid = true;
}
$sql1 = "SELECT g_email FROM `garage_owner` WHERE `g_email` = '$email' ";
$result1 = mysqli_query($conn, $sql1);
$num1 = mysqli_fetch_array($result1);
if ($num1 > 0) {
if ($password == $confirmpassword && $passwordvalid == false) {
$hashpassword = password_hash($password, PASSWORD_DEFAULT);
$sql2 = "UPDATE garage_owner set g_password='$hashpassword' where g_email='$email'";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
$alertsuccess = "Password reset successfull!!";
}
} else {
$alerterror = "Password not match or Password should be at least 8 characters in length and should include at least one upper case letter, one number, and one special character.";
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="MYMECHANIC_CSS/style.css">
<title>Mymechanic | Reset Password</title>
</head>
<body>
<!-- include navbar start -->
<?php include 'partials\_navbar.php'; ?>
<!-- include navbar End -->
<?php
if ($alerterror)
echo '<div class="alert alert-danger alert-dismissible fade show my-2 mx-2" role="alert">
<i class="bi bi-exclamation-triangle-fill" style="font-size:20px"> </i><strong>Sorry!! </strong>' . $alerterror . '
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
?>
<?php
if ($alertsuccess)
echo '<div class="alert alert-success alert-dismissible fade show my-2 mx-2" role="alert">
<i class="bi bi-check-circle-fill" style="font-size:20px"> </i><strong>Success!! </strong>' . $alertsuccess . '
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
?>
<!-- customer form html start -->
<?php
$respath ="";
if(isset($_GET['crmail'])){
$respath = "Reset_password.php?crmail=".$email;
}
else{
$respath = "Reset_password.php?grmail=".$email;
}
?>
<div class="form-container">
<div class="field-container">
<form method="POST" action="<?php echo $respath; ?>" class="customer-form" enctype="multipart/form-data">
<h2 class="form-field" style="font-weight: bold; color:white; text-align:center">Reset Password <i class="bi bi-card-checklist"></i></h2>
<hr style="height:4px; background-color: Red;">
<div class="form-field mb-3">
<p style="font-weight: bold; color:white">Enter New Password:</p>
<input type="password" maxlength="30" class="form-control" id="password" name="password" required="required" />
</div>
<div class="form-field mb-3 ">
<p style="font-weight: bold; color:white">Confirm New Password:</p>
<input type="password" maxlength="30" class="form-control" id="confirmpassword" name="confirmpassword" required="required" />
</div>
<hr style="height:4px; background-color: white;">
<div class="button-container">
<button class="customer-submit mb-1" type="submit">Update Password</button>
<button class="customer-submit mb-1" type="reset">Reset</button>
</div>
</form>
</div>
</div>
<!-- customer form html End -->
<!-- Footer End -->
<?php include 'partials/_footer.php'; ?>
<!-- Footer End -->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="MYMECHANIC_JS/mechanic.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>