forked from che0/greybox
-
Notifications
You must be signed in to change notification settings - Fork 3
/
clovek.pw.edit.exec.inc
83 lines (68 loc) · 2.49 KB
/
clovek.pw.edit.exec.inc
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
<?php
/*
* greybox
* $Id: clovek.pw.edit.exec.inc,v 1.6 2005/01/15 15:14:12 che0 Exp $
*/
if($_REQUEST["n1"] != $_REQUEST["n2"]) {
pg_achtung($lang["passwords do not match"]);
return;
}
if($_REQUEST["n1"] == "" && !isset($_REQUEST["delete"])) {
pg_achtung($lang["refusing to set empty password"]);
return;
}
$clovek_id = $_REQUEST["clovek_id"];
$username = $_REQUEST["username"];
$pw_n = md5($_REQUEST["n1"]);
$pw_o = md5($_REQUEST["old"]);
if (isset($_REQUEST["password"])) {
// check user is changing his own pw
if ($clovek_id != $_SESSION["user_clovek_ID"]) {
pg_achtung($lang["access denied"]);
return;
}
// check old password
if (cpdb_fetch_one_value("select password from login where clovek_ID = :clovek_id and password = :password", array(":clovek_id"=>$clovek_id, ":password"=>$pw_o)) != $pw_o) {
pg_achtung($lang["bad old password"]);
return;
}
// change it
if (cpdb_exec("update login set password = :password where clovek_ID = :clovek_id",array(":clovek_id"=>$clovek_id, ":password"=>$pw_n))) {
pg_achtung($lang["password changed"]);
include("clovek.inc");
}
} else {
// ensure user has approprite privileges
if ($GLOBALS["cps_lidi"] < 3) {
pg_achtung($lang["access denied"]);
return;
}
if (isset($_REQUEST["add"])) {
if (cpdb_fetch_one_value("select count(*) from login where username = :username",array(":username"=>$username)) > 0) {
pg_achtung($lang["duplicate username"]);
return;
}
// add account
if (cpdb_exec("insert into login (clovek_ID, username, password) values (:clovek_id, :username, :password)", array(":clovek_id"=>$clovek_id, ":username"=>$username, ":password"=>$pw_n))) {
pg_achtung($lang["account insert ok"]);
include("clovek.inc");
}
} elseif (isset($_REQUEST["save"])) {
if (cpdb_fetch_one_value("select count(*) from login where username = :username and clovek_ID != :clovek_id",array(":username"=>$username, ":clovek_id"=>$clovek_id)) > 0) {
pg_achtung($lang["duplicate username"]);
return;
}
// change account
if (cpdb_exec("update login set username = :username, password = :password where clovek_ID = :clovek_id", array(":clovek_id"=>$clovek_id, ":username"=>$username, ":password"=>$pw_n))) {
pg_achtung($lang["account update ok"]);
include("clovek.inc");
}
} elseif (isset($_REQUEST["delete"])) {
// delete account
if (cpdb_exec("delete from login where clovek_ID = :clovek_id", array(":clovek_id"=>$clovek_id))) {
pg_achtung($lang["account delete ok"]);
include("clovek.inc");
}
}
}
?>