X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/59d032c86464658baee13fad479403f411c2c56e..89ba7ba42b9f5eeca0e55e62ab2f5cf0494e0be0:/Classes/class-paneluser.php diff --git a/Classes/class-paneluser.php b/Classes/class-paneluser.php index c813992..217226f 100644 --- a/Classes/class-paneluser.php +++ b/Classes/class-paneluser.php @@ -54,6 +54,8 @@ class PanelUser $user["id"] = $id; $user["object"] = NULL; Hook::run(HOOKTYPE_USER_LOOKUP, $user); + if ($user['object'] === null) + return; /* no auth module loaded? */ foreach ($user['object'] as $key => $value) $this->$key = $value; } @@ -63,13 +65,40 @@ class PanelUser * @param string $input * @return bool */ - function password_verify(string $input) : bool + function password_verify(string $password, bool &$hash_needs_updating = false) : bool { - if (password_verify($input, $this->passhash)) - return true; + GLOBAL $config; + $hash_needs_updating = false; + + if (str_starts_with($this->passhash, "peppered:")) + { + /* Argon2 with pepper */ + $password = hash_hmac("sha256", $password, $config['secrets']['pepper']); + if (password_verify($password, substr($this->passhash,9))) + return true; + } else { + /* Old standard argon2 */ + if (password_verify($password, $this->passhash)) + { + $hash_needs_updating = true; + return true; + } + } return false; } + /** + * Generate hash of user's password + * @param string $password + * @return string + */ + public static function password_hash(string $password) : string + { + GLOBAL $config; + $input = hash_hmac("sha256", $password, $config['secrets']['pepper']); + return "peppered:".password_hash($input, PASSWORD_ARGON2ID); + } + /** * Add user meta data * @param string $key @@ -184,7 +213,7 @@ function create_new_user(array &$user) : bool throw new Exception("Attempted to add user without specifying user_name or user_pass"); $user['user_name'] = htmlspecialchars($user['user_name']); - $user['user_pass'] = password_hash($user['user_pass'], PASSWORD_ARGON2ID); + $user['user_pass'] = PanelUser::password_hash($user['user_pass']); $user['fname'] = (isset($user['fname'])) ? htmlspecialchars($user['fname']) : NULL; $last['lname'] = (isset($user['lname'])) ? htmlspecialchars($user['lname']) : NULL; $user['user_bio'] = (isset($user['user_bio'])) ? htmlspecialchars($user['user_bio']) : NULL; @@ -212,12 +241,7 @@ function create_new_user(array &$user) : bool */ function unreal_get_current_user() : PanelUser|bool { - if (!isset($_SESSION)) - { - session_set_cookie_params(3600); - session_start(); - } - if (isset($_SESSION['id'])) + if (isset($_SESSION) && isset($_SESSION['id'])) { $user = new PanelUser(NULL, $_SESSION['id']); if ($user->id) @@ -326,3 +350,77 @@ function generate_panel_user_permission_table($user) get_panel_user_permission_list(), // SuperAdmin can do everything + "Read Only" => [], // Read Only can do nothing + ]; + + Hook::run(HOOKTYPE_USER_ROLE_LIST, $list); + return $list; +} + +function generate_role_list($list) +{ + $list2 = get_panel_user_permission_list(); + ?> +
Roles List:
+
+
+
+ + $slug) {?> +
+
+ +
+ +
+
+
+ +
+ + +
+ + +
$slug) + { + $attributes = ""; + $attributes .= ($role == "Super Admin" || $role == "Read Only") ? "disabled " : ""; + + ?> +
+
+
+ name="permissions[]" value="" type="checkbox"> +
+
+ "> +
+ +
+
+
+
+
+ + +

+ +