-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange_password.php
53 lines (43 loc) · 1.99 KB
/
change_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
<?php
include('functions.php');
$status = ["status" => "error", "msg" => "Password is missing."];
$username = null;
if(array_key_exists("username", $_GET) || array_key_exists("email", $_GET)) {
if(array_key_exists("email", $_GET)) {
$username = get_single_value_from_query("select username from tfd_db.login where email = ".esc($_GET["email"]));
} else if(array_key_exists("username", $_GET)) {
$username = $_GET["username"];
}
}
if(!is_null($username)) {
if(can_edit_user($username)) {
if(array_key_exists("password", $_GET) && ($_GET["password"] != "")) {
$password = $_GET["password"];
if(strlen($password) > 7) {
if(username_exists($username)) {
if($username != "") {
$salt = get_single_value_from_query("select salt from tfd_db.login where username = ".esc($username));
$query = "update tfd_db.login set pw = ".esc(hash("sha256", $password.$salt))." where username = ".esc($username);
run_query($query);
$status = ["status" => "ok", "msg" => "The password has changed."];
} else {
$status["msg"] = "The username is empty.";
}
} else {
$status["msg"] = "This username doesn't exist.";
}
} else {
$status["msg"] = "The password must be at least 8 characters long.";
}
} else {
$status["msg"] = "Please insert a password.";
}
} else {
$status["msg"] = "You don't have the permission to edit this user.";
}
} else {
$status["msg"] = "Cannot determine username.";
}
header('Content-type: application/json');
print json_encode($status);
?>