-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchangePW.php
52 lines (46 loc) · 1.52 KB
/
changePW.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
<?php
$servername = "localhost";
$name = "antinc";
$password = "AntInc_AntInc123";
$dbname = "Ant_Planner";
$conn = mysqli_connect($servername, $name, $password, $dbname);
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
if(!$_POST) {
die("This file cannot be accessed directly!");
}
$password = $_POST["newPassword"];
$password2 = $_POST["newPassword2"];
$id = intval($_POST["id"]);
$valid = true;
$errorMsg = "<div class='alert alert-danger' role='alert'><ul>";
$passwordValidation = '/^(?=.*[a-zA-Z])(?=.*[0-9])/';
if($password !== $password2) {
$errorMsg .= "<li>Two passwords do not match</li>";
$valid = false;
}
if(!(preg_match($passwordValidation, $password))){
$errorMsg .= "<li>The password should contain both letters and numbers</li>";
$valid = false;
}
if (strlen($password) < 6) {
$errorMsg .= "<li>The password should contain at least 6 characters</li>";
$valid = false;
}
if (strlen($password) > 15) {
$errorMsg .= "<li>The password should contain at most 15 characters</li>";
$valid = false;
}
if($valid){
$sql = "update Users set password='".$password."' where id='".$id."'";
if($conn->query($sql) === true) {
echo "<div class='alert alert-success' role='alert'><strong>Password Changed!</strong><ul><li>Please log in again.</li></ul><strong id='redirect'></strong></div>";
} else {
echo "<div class='alert alert-danger' role='alert'><p>Connection error. Please try again later.</p></div>";
}
} else {
echo $errorMsg."</ul></div>";
}
?>
<!--