X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAuth%2FPassword.pm;h=5ae75eac5469556a26b1fc5db9d4cdd0fdbd0b72;hb=8e1151555c7383bdd4e9baca68e6fa29b48cbd29;hp=5a17203c53c5035ecc75d461190c5c73424346cb;hpb=1c385c602908735c3be266b1470b301050650fd3;p=kivitendo-erp.git diff --git a/SL/Auth/Password.pm b/SL/Auth/Password.pm index 5a17203c5..5ae75eac5 100644 --- a/SL/Auth/Password.pm +++ b/SL/Auth/Password.pm @@ -3,29 +3,24 @@ package SL::Auth::Password; use strict; use Carp; +use Digest::MD5 (); +use Digest::SHA (); sub hash { my ($class, %params) = @_; - if (!$params{algorithm}) { - $params{algorithm} = 'SHA1'; - $params{fallback_algorithm} = 'MD5'; - } + $params{algorithm} ||= 'SHA256S'; - if ($params{algorithm} eq 'SHA1') { - if (eval { require Digest::SHA1; 1 }) { - return '{SHA1}' . Digest::SHA1::sha1_hex($params{password}); + my $salt = $params{algorithm} =~ m/S$/ ? $params{login} : ''; - } elsif ($params{fallback_algorithm}) { - return $class->hash_password(%params, algorithm => $params{fallback_algorithm}); + if ($params{algorithm} =~ m/^SHA256/) { + return '{' . $params{algorithm} . '}' . Digest::SHA::sha256_hex($salt . $params{password}); - } else { - die 'Digest::SHA1 not available'; - } + } elsif ($params{algorithm} =~ m/^SHA1/) { + return '{' . $params{algorithm} . '}' . Digest::SHA::sha1_hex($salt . $params{password}); - } elsif ($params{algorithm} eq 'MD5') { - require Digest::MD5; - return '{MD5}' . Digest::MD5::md5_hex($params{password}); + } elsif ($params{algorithm} =~ m/^MD5/) { + return '{' . $params{algorithm} . '}' . Digest::MD5::md5_hex($salt . $params{password}); } elsif ($params{algorithm} eq 'CRYPT') { return '{CRYPT}' . crypt($params{password}, substr($params{login}, 0, 2)); @@ -40,7 +35,15 @@ sub hash_if_unhashed { my ($algorithm, $password) = $class->parse($params{password}, 'NONE'); - return $algorithm eq 'NONE' ? $class->hash(%params) : $params{password}; + return $params{password} unless $algorithm eq 'NONE'; + + if ($params{look_up_algorithm}) { + my $stored_password = $params{auth}->get_stored_password($params{login}); + my ($stored_algorithm) = $class->parse($stored_password); + $params{algorithm} = $stored_algorithm; + } + + return $class->hash(%params); } sub parse {