Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e0c3dcb8

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID e0c3dcb8647d811bf327ad3f50175acb3289a986
  • Vorgänger 7d42e176
  • Nachfolger f8250919

Default-Passwort-Algo: SHA256 mit Salzen durch Login

Unterschiede anzeigen:

SL/Auth/Password.pm
8 8
  my ($class, %params) = @_;
9 9

  
10 10
  if (!$params{algorithm}) {
11
    $params{algorithm}          = 'SHA1';
11
    $params{algorithm}          = 'SHA256S';
12 12
    $params{fallback_algorithm} = 'MD5';
13 13
  }
14 14

  
15
  if ($params{algorithm} eq 'SHA1') {
16
    if (eval { require Digest::SHA1; 1 }) {
17
      return '{SHA1}' . Digest::SHA1::sha1_hex($params{password});
15

  
16
  my $salt = $params{algorithm} =~ m/S$/ ? $params{login} : '';
17

  
18
  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_password(%params, algorithm => $params{fallback_algorithm});
24

  
25
    } else {
26
      die 'Digest::SHA is not available';
27
    }
28

  
29
  } 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});
18 35

  
19 36
    } elsif ($params{fallback_algorithm}) {
20 37
      return $class->hash_password(%params, algorithm => $params{fallback_algorithm});
21 38

  
22 39
    } else {
23
      die 'Digest::SHA1 not available';
40
      die 'Neither Digest::SHA nor Digest::SHA1 is available';
24 41
    }
25 42

  
26
  } elsif ($params{algorithm} eq 'MD5') {
43
  } elsif ($params{algorithm} =~ m/^MD5/) {
27 44
    require Digest::MD5;
28
    return '{MD5}' . Digest::MD5::md5_hex($params{password});
45
    return '{' . $params{algorithm} . '}' . Digest::MD5::md5_hex($salt . $params{password});
29 46

  
30 47
  } elsif ($params{algorithm} eq 'CRYPT') {
31 48
    return '{CRYPT}' . crypt($params{password}, substr($params{login}, 0, 2));

Auch abrufbar als: Unified diff