mirror of
https://github.com/webmin/webmin.git
synced 2026-05-04 22:30:33 +01:00
Don't use an invalid salt when encrypting password
This commit is contained in:
@@ -24,12 +24,17 @@ return undef;
|
||||
sub encrypt_md5
|
||||
{
|
||||
local $passwd = $_[0];
|
||||
local $salt = $_[1];
|
||||
local $magic = '$1$';
|
||||
local $salt = $_[1] || substr(time(), -8);
|
||||
if ($salt =~ /^\$1\$([^\$]+)/) {
|
||||
# Extract actual salt from already encrypted password
|
||||
$salt = $1;
|
||||
}
|
||||
if ($salt !~ /^[a-z0-9\/]{8}$/i) {
|
||||
# Non-MD5 salt
|
||||
$salt = undef;
|
||||
}
|
||||
$salt ||= substr(time(), -8);
|
||||
|
||||
# Use built-in crypt support for MD5, if we can
|
||||
if (&unix_crypt_supports_md5()) {
|
||||
@@ -162,6 +167,10 @@ sub encrypt_blowfish
|
||||
local ($passwd, $salt) = @_;
|
||||
local ($plain, $base64);
|
||||
eval "use Crypt::Eksblowfish::Bcrypt";
|
||||
if ($salt !~ /^\$2a\$/) {
|
||||
# Invalid salt for Blowfish
|
||||
$salt = undef;
|
||||
}
|
||||
if (!$salt) {
|
||||
# Generate a 22-character base-64 format salt
|
||||
&seed_random();
|
||||
|
||||
@@ -1796,6 +1796,10 @@ elsif ($format == 2) {
|
||||
}
|
||||
else {
|
||||
# Just do old-style crypt() DES encryption
|
||||
if ($salt !~ /^[a-z0-9]{2}/i) {
|
||||
# Un-usable non-DES salt
|
||||
$salt = undef;
|
||||
}
|
||||
$salt ||= chr(int(rand(26))+65) . chr(int(rand(26))+65);
|
||||
return &unix_crypt($pass, $salt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user