|
9 | 9 | function userGet($userID) { |
10 | 10 | global $conf; |
11 | 11 |
|
12 | | - $json = file_get_contents($conf["dir"]["data"]."/users.json"); |
| 12 | + $userFile = $conf["dir"]["data"]."/users.json"; |
| 13 | + if (!file_exists($userFile)) { |
| 14 | + $return["status"] = "fail"; |
| 15 | + $return["code"] = 4; |
| 16 | + $return["string"] = "Could not find user database"; |
| 17 | + return $return; |
| 18 | + } |
| 19 | + |
| 20 | + $json = file_get_contents($userFile); |
13 | 21 |
|
14 | 22 | $uDB = json_decode($json,true); |
15 | 23 | //if ($_SESSION["ohv"]["projects"][$projectID]["user"]["role"] != "admin") { |
@@ -81,7 +89,7 @@ function userRegister($name, $mail, $passwd) { |
81 | 89 | $user["user"][$user["user-increment"]]["name"] = $name; |
82 | 90 | $user["user"][$user["user-increment"]]["mail"] = strtolower($mail); |
83 | 91 | $user["user"][$user["user-increment"]]["registrationDate"] = time(); |
84 | | - $user["user"][$user["user-increment"]]["passwd"] = hash("sha256",$passwd.$user["user"][$user["user-increment"]]["registrationDate"]); |
| 92 | + $user["user"][$user["user-increment"]]["passwd"] = password_hash($passwd, PASSWORD_DEFAULT); |
85 | 93 | $user["user"][$user["user-increment"]]["role"] = (($tmpFirstUser) ? "admin" : $configDB["defaultUserRole"]); |
86 | 94 | $user["user"][$user["user-increment"]]["active"] = (($tmpFirstUser) ? 1 : (($configDB["userNeedsConfirmation"]) ? 0 : 1)); |
87 | 95 | $user["user"][$user["user-increment"]]["lastLogin"] = ""; |
@@ -155,7 +163,7 @@ function userLogin($mail, $passwd) { |
155 | 163 | $file->close(); |
156 | 164 | return $return; |
157 | 165 | } |
158 | | - if ($user["passwd"] != hash("sha256",$passwd.$user["registrationDate"])) { |
| 166 | + if (!password_verify($passwd, $user["passwd"])) { |
159 | 167 | $return["status"] = "fail"; |
160 | 168 | $return["code"] = 3; |
161 | 169 | $return["string"] = "Wrong password!"; |
@@ -328,7 +336,7 @@ function userChange($userID,$mail,$name,$passwd,$color,$role,$active) { |
328 | 336 | $userdb["user"][$userID]["mail"] = $mail; |
329 | 337 | $userdb["user"][$userID]["color"] = $color; |
330 | 338 | $userdb["user"][$userID]["active"] = ((($active==="1" || $active==="0") && (($_SESSION["ohv"]["user"]["role"] == "admin"))) ? $active*1 : $userdb["user"][$userID]["active"]*1); |
331 | | - $userdb["user"][$userID]["passwd"] = ($passwd) ? hash("sha256",$passwd.$userdb["user"][$userID]["registrationDate"]) : $userdb["user"][$userID]["passwd"]; |
| 339 | + $userdb["user"][$userID]["passwd"] = ($passwd) ? password_hash($passwd, PASSWORD_DEFAULT) : $userdb["user"][$userID]["passwd"]; |
332 | 340 | $file->write(json_encode($userdb, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
333 | 341 | $return["status"] = "success"; |
334 | 342 | $return["string"] = "userdata updated"; |
|
0 commit comments