Revision 9d4c2b6c
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/Auth/Password.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
|
5 | 5 |
use Carp; |
6 |
use Digest::MD5 (); |
|
7 |
use Digest::SHA (); |
|
6 | 8 |
|
7 | 9 |
sub hash { |
8 | 10 |
my ($class, %params) = @_; |
9 | 11 |
|
10 |
if (!$params{algorithm}) { |
|
11 |
$params{algorithm} = 'SHA256S'; |
|
12 |
$params{fallback_algorithm} = 'MD5'; |
|
13 |
} |
|
14 |
|
|
12 |
$params{algorithm} ||= 'SHA256S'; |
|
15 | 13 |
|
16 | 14 |
my $salt = $params{algorithm} =~ m/S$/ ? $params{login} : ''; |
17 | 15 |
|
18 | 16 |
if ($params{algorithm} =~ m/^SHA256/) { |
19 |
if (eval { require Digest::SHA; 1 }) { |
|
20 |
return '{' . $params{algorithm} . '}' . Digest::SHA::sha256_hex($salt . $params{password}); |
|
21 |
|
|
22 |
} elsif ($params{fallback_algorithm}) { |
|
23 |
return $class->hash(%params, algorithm => $params{fallback_algorithm}); |
|
24 |
|
|
25 |
} else { |
|
26 |
die 'Digest::SHA is not available'; |
|
27 |
} |
|
17 |
return '{' . $params{algorithm} . '}' . Digest::SHA::sha256_hex($salt . $params{password}); |
|
28 | 18 |
|
29 | 19 |
} elsif ($params{algorithm} =~ m/^SHA1/) { |
30 |
if (eval { require Digest::SHA; 1 }) { |
|
31 |
return '{' . $params{algorithm} . '}' . Digest::SHA::sha1_hex($salt . $params{password}); |
|
32 |
|
|
33 |
} elsif (eval { require Digest::SHA1; 1 }) { |
|
34 |
return '{' . $params{algorithm} . '}' . Digest::SHA1::sha1_hex($salt . $params{password}); |
|
35 |
|
|
36 |
} elsif ($params{fallback_algorithm}) { |
|
37 |
return $class->hash(%params, algorithm => $params{fallback_algorithm}); |
|
38 |
|
|
39 |
} else { |
|
40 |
die 'Neither Digest::SHA nor Digest::SHA1 is available'; |
|
41 |
} |
|
20 |
return '{' . $params{algorithm} . '}' . Digest::SHA::sha1_hex($salt . $params{password}); |
|
42 | 21 |
|
43 | 22 |
} elsif ($params{algorithm} =~ m/^MD5/) { |
44 |
require Digest::MD5; |
|
45 | 23 |
return '{' . $params{algorithm} . '}' . Digest::MD5::md5_hex($salt . $params{password}); |
46 | 24 |
|
47 | 25 |
} elsif ($params{algorithm} eq 'CRYPT') { |
Auch abrufbar als: Unified diff
Modul Digest::SHA1 auch nicht mehr als Fallback versuchen
Wird schlicht nicht mehr benötigt: Digest::SHA kam mit Perl 5.9.3 in
Core, und wir setzen 5.10.1 voraus.