Refactor support for pre-hashed passwords (#4024)
parent
43146b23c9
commit
4feceb08da
|
@ -88,23 +88,29 @@ function hash_password($password) {
|
||||||
// in case default pass scheme is not defined, falling back to BLF-CRYPT.
|
// in case default pass scheme is not defined, falling back to BLF-CRYPT.
|
||||||
global $default_pass_scheme;
|
global $default_pass_scheme;
|
||||||
$pw_hash = NULL;
|
$pw_hash = NULL;
|
||||||
switch (strtoupper($default_pass_scheme)) {
|
// support pre-hashed passwords
|
||||||
case "SSHA":
|
if (preg_match('/^{(ARGON2I|ARGON2ID|BLF-CRYPT|CLEAR|CLEARTEXT|CRYPT|DES-CRYPT|LDAP-MD5|MD5|MD5-CRYPT|PBKDF2|PLAIN|PLAIN-MD4|PLAIN-MD5|PLAIN-TRUNC|PLAIN-TRUNC|SHA|SHA1|SHA256|SHA256-CRYPT|SHA512|SHA512-CRYPT|SMD5|SSHA|SSHA256|SSHA512)}/i', $password)) {
|
||||||
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
$pw_hash = $password;
|
||||||
$pw_hash = "{SSHA}".base64_encode(hash('sha1', $password . $salt_str, true) . $salt_str);
|
}
|
||||||
break;
|
else {
|
||||||
case "SSHA256":
|
switch (strtoupper($default_pass_scheme)) {
|
||||||
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
case "SSHA":
|
||||||
$pw_hash = "{SSHA256}".base64_encode(hash('sha256', $password . $salt_str, true) . $salt_str);
|
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
||||||
break;
|
$pw_hash = "{SSHA}".base64_encode(hash('sha1', $password . $salt_str, true) . $salt_str);
|
||||||
case "SSHA512":
|
break;
|
||||||
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
case "SSHA256":
|
||||||
$pw_hash = "{SSHA512}".base64_encode(hash('sha512', $password . $salt_str, true) . $salt_str);
|
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
||||||
break;
|
$pw_hash = "{SSHA256}".base64_encode(hash('sha256', $password . $salt_str, true) . $salt_str);
|
||||||
case "BLF-CRYPT":
|
break;
|
||||||
default:
|
case "SSHA512":
|
||||||
$pw_hash = "{BLF-CRYPT}" . password_hash($password, PASSWORD_BCRYPT);
|
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
|
||||||
break;
|
$pw_hash = "{SSHA512}".base64_encode(hash('sha512', $password . $salt_str, true) . $salt_str);
|
||||||
|
break;
|
||||||
|
case "BLF-CRYPT":
|
||||||
|
default:
|
||||||
|
$pw_hash = "{BLF-CRYPT}" . password_hash($password, PASSWORD_BCRYPT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $pw_hash;
|
return $pw_hash;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1062,13 +1062,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// support pre hashed passwords
|
$password_hashed = hash_password($password);
|
||||||
if (preg_match('/^{(ARGON2I|ARGON2ID|BLF-CRYPT|CLEAR|CLEARTEXT|CRYPT|DES-CRYPT|LDAP-MD5|MD5|MD5-CRYPT|PBKDF2|PLAIN|PLAIN-MD4|PLAIN-MD5|PLAIN-TRUNC|PLAIN-TRUNC|SHA|SHA1|SHA256|SHA256-CRYPT|SHA512|SHA512-CRYPT|SMD5|SSHA|SSHA256|SSHA512)}/i', $password)) {
|
|
||||||
$password_hashed = $password;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$password_hashed = hash_password($password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$_SESSION['return'][] = array(
|
$_SESSION['return'][] = array(
|
||||||
|
|
Loading…
Reference in New Issue