Repository navigation
Expand file tree
/
Copy pathreset_password.php
More file actions
128 lines (115 loc) · 5.1 KB
/
Copy pathreset_password.php
File metadata and controls
128 lines (115 loc) · 5.1 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
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
<?php
session_start();
$mysql_connect = mysqli_connect("localhost", "id16543739_cdbat", "Cypress@12345", "id16543739_cypress");
// check if database connected properly
if (!$mysql_connect) {
die(mysqli_connect_error());
}
?>
<head>
<title>Account Settings</title>
<meta charset='UTF-8'>
<link rel="stylesheet" href="">
</head>
<body>
<?php
include 'header.php';
?>
<div style="width:50%; margin: auto;">
<form method="POST" id="reset_password" name="reset_password" action="#">
<table style="width:100%">
<tr>
<th></th>
<th></th>
</tr>
<tr>
<td>
<label for="email">Email:</label>
</td>
<td>
<input type='email' name='email' id='email'>
</td>
</tr>
<tr>
<td>
<label for="password"><?php checkLanguage("Password:", "Le Mot de Passe:"); ?></label>
</td>
<td>
<input type='password' name='password' id='password' >
</td>
</tr>
<tr>
<td>
<label for="password2"><?php checkLanguage("Confirm New Password::", "Confirmer le Nouveau Mot de Passe:"); ?></label>
</td>
<td>
<input type='password' name='password2' id='password2'>
</td>
</tr>
<tr>
<td>
<label for="security"><?php checkLanguage("Secret Question:", "Question Secrète:"); ?></label>
</td>
<td>
<input type='input' name='security' id='security'>
</td>
</tr>
<table>
<button type="submit" id="reset_password" name="reset_password"><?php checkLanguage("Reset Password", "Réinitialiser le Mot de Passe"); ?></button>
<form>
<div>
</body>
<?php
// user tried to create new acount
if(isset($_POST['reset_password'])){
// get login info
$email = strtolower($_POST['email']);
$password = $_POST['password'];
$password2 = $_POST['password2'];
$security = $_POST['security'];
// select everything from the table Accounts where the column email = user email and security question is user answer
$sqlQuery = "SELECT * FROM Accounts WHERE email ='$email' AND security ='$security'";
// get query result
$queryResult = $mysql_connect -> query($sqlQuery);
$queryRows = mysqli_num_rows($queryResult);
// account found
if($queryRows == 1){
// password not matching
if (strcmp($password, $password2) !== 0) {
$message = checkLanguageAlert("New Password and Confirm New Password are not the same. Please try again.", "Le nouveau mot de passe et la confirmation du nouveau mot de passe ne sont pas les mêmes. Veuillez réessayer.");
echo "<script type='text/javascript'>alert('$message');</script>";
}
// blank entry
elseif ($email == "" ) {
$message = checkLanguageAlert("You must enter an email.", "Vous devez saisir un email.");
echo "<script type='text/javascript'>alert('$message');</script>";
}
elseif ($password == "") {
$message = checkLanguageAlert("You must enter a password.", "Vous devez entrer un mot de passe.");
echo "<script type='text/javascript'>alert('$message');</script>";
}
else {
$sqlQuery = "UPDATE Accounts SET password = '$password' WHERE email ='$email' AND security ='$security'";
// get query result
$queryResult = $mysql_connect -> query($sqlQuery);
// message
$message = checkLanguageAlert("Your new password is ", "Votre nouveau mot de passe est ");
$msg = $message . $password;
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email (to, subject, message, from)
mail($email,'Password Reset Cypress', $msg, 'cypress@email.com');
}
$message = checkLanguageAlert("Password changed successfully.", "Le mot de passe a été changé avec succès");
echo "<script type='text/javascript'>alert('$message');</script>";
echo("<br>");
$message = checkLanguage("Email has been sent.", "L'email a été envoyé.");
echo "<script type='text/javascript'>alert('$message');</script>";
}
// no such account or security
else {
$message = checkLanguageAlert("The email or secret question is incorrect please try again.", "L'email ou la question secrète est incorrecte, veuillez réessayer.");
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
?>