see https://github.com/postfixadmin/postfixadmin/issues/422 - not all variants of MySQL have RANDOM_BYTES()

This commit is contained in:
David Goodwin committed 2021-01-16 21:42:02 +00:00
1 parent dd7d94912b
commit 189bd583a0
1 file changed
+2 -1
+2 -1
View File
@@ -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'];