1 package SL::Auth::Password;
8 my ($class, %params) = @_;
10 if (!$params{algorithm}) {
11 $params{algorithm} = 'SHA1';
12 $params{fallback_algorithm} = 'MD5';
15 if ($params{algorithm} eq 'SHA1') {
16 if (eval { require Digest::SHA1; 1 }) {
17 return '{SHA1}' . Digest::SHA1::sha1_hex($params{password});
19 } elsif ($params{fallback_algorithm}) {
20 return $class->hash_password(%params, algorithm => $params{fallback_algorithm});
23 die 'Digest::SHA1 not available';
26 } elsif ($params{algorithm} eq 'MD5') {
28 return '{MD5}' . Digest::MD5::md5_hex($params{password});
30 } elsif ($params{algorithm} eq 'CRYPT') {
31 return '{CRYPT}' . crypt($params{password}, substr($params{login}, 0, 2));
34 croak 'Unsupported hash algorithm ' . $params{algorithm};
39 my ($class, $password) = @_;
41 return ($1, $2) if $password =~ m/^\{ ([^\}]+) \} (.+)/x;
42 return ('CRYPT', $password);