From 189bd583a07afb1bee6533669f61d735169cea74 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 16 Jan 2021 21:41:45 +0000 Subject: [PATCH] see https://github.com/postfixadmin/postfixadmin/issues/422 - not all variants of MySQL have RANDOM_BYTES() --- functions.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions.inc.php b/functions.inc.php index 638c4254..f4a810ba 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -943,7 +943,8 @@ function _pacrypt_mysql_encrypt($pw, $pw_db = '') { } else { // see https://security.stackexchange.com/questions/150687/is-it-safe-to-use-the-encrypt-function-in-mysql-to-hash-passwords // if no existing password, use a random SHA512 salt. - $res= db_query_one("SELECT ENCRYPT(:pw, CONCAT('$6$', SHA2(RANDOM_BYTES(64), '256'))) as result", ['pw' => $pw]); + $salt = _php_crypt_generate_crypt_salt(); + $res= db_query_one("SELECT ENCRYPT(:pw, CONCAT('$6$', '$salt')) as result", ['pw' => $pw]); } return $res['result'];