mirror of
https://github.com/webmin/webmin.git
synced 2026-06-05 04:40:24 +01:00
Fix encrypt_sha512 so it doesn't always fall back to crypt
This commit is contained in:
11
miniserv.pl
11
miniserv.pl
@@ -6779,15 +6779,14 @@ return $newhash eq $hash;
|
||||
}
|
||||
|
||||
# encrypt_sha512(password, [salt])
|
||||
# Hashes a password, possibly with the given salt, with SHA512
|
||||
# Hashes a password, possibly with the given salt, with SHA512. The salt
|
||||
# arg may be a full $6$salt$hash form (verification) or a bare $6$salt$
|
||||
# (fresh hashing) — either way it must be passed to crypt() intact so
|
||||
# crypt() selects SHA512. Only synthesise a new salt when none is given.
|
||||
sub encrypt_sha512
|
||||
{
|
||||
my ($passwd, $salt) = @_;
|
||||
if ($salt =~ /^\$6\$([^\$]+)/) {
|
||||
# Extract actual salt from already encrypted password
|
||||
$salt = $1;
|
||||
}
|
||||
$salt ||= '$6$'.substr(time(), -8).'$';
|
||||
$salt = '$6$'.substr(time(), -8).'$' if (!$salt || $salt !~ /^\$6\$/);
|
||||
return crypt($passwd, $salt);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user