summaryrefslogtreecommitdiffstats
path: root/inc/crypto.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2023-05-22 15:33:44 +0200
committerSimon Rettberg2023-05-22 15:33:44 +0200
commit65a88e9c53341de0dc4f71d0497f78df20702107 (patch)
tree21dcfe8d2924d3525d6eaa361d2b6c65dd1b6332 /inc/crypto.inc.php
parent[backup] Lang (diff)
downloadslx-admin-65a88e9c53341de0dc4f71d0497f78df20702107.tar.gz
slx-admin-65a88e9c53341de0dc4f71d0497f78df20702107.tar.xz
slx-admin-65a88e9c53341de0dc4f71d0497f78df20702107.zip
Type annotations, better RNG
Diffstat (limited to 'inc/crypto.inc.php')
-rw-r--r--inc/crypto.inc.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/inc/crypto.inc.php b/inc/crypto.inc.php
index eb0d344f..d26a94ab 100644
--- a/inc/crypto.inc.php
+++ b/inc/crypto.inc.php
@@ -8,20 +8,22 @@ class Crypto
* which translates to ~130 bit salt
* and 5000 rounds of hashing with SHA-512.
*/
- public static function hash6($password)
+ public static function hash6(string $password): string
{
$salt = substr(str_replace('+', '.',
- base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 16);
+ base64_encode(Util::randomBytes(16))), 0, 16);
$hash = crypt($password, '$6$' . $salt);
- if (strlen($hash) < 60) ErrorHandler::traceError('Error hashing password using SHA-512');
+ if ($hash === null || strlen($hash) < 60) {
+ ErrorHandler::traceError('Error hashing password using SHA-512');
+ }
return $hash;
}
/**
- * Check if the given password matches the given cryp hash.
+ * Check if the given password matches the given crypt hash.
* Useful for checking a hashed password.
*/
- public static function verify($password, $hash)
+ public static function verify(string $password, string $hash): bool
{
return crypt($password, $hash) === $hash;
}