Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d3d6cb31

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID d3d6cb31bbeec3a6eba3ff41990a2748303f5851
  • Vorgänger 16f91f23
  • Nachfolger 8ed92861

Fall 'kein Hash-Algorithmus angegeben' bei alten Passwörtern richtig behandeln

Unterschiede anzeigen:

SL/Auth.pm
165 165
sub store_credentials_in_session {
166 166
  my ($self, %params) = @_;
167 167

  
168
  $params{password} = SL::Auth::Password->hash_if_unhashed(login => $params{login}, password => $params{password})
169
    unless $self->{authenticator}->requires_cleartext_password;
168
  if (!$self->{authenticator}->requires_cleartext_password) {
169
    $params{password} = SL::Auth::Password->hash_if_unhashed(login             => $params{login},
170
                                                             password          => $params{password},
171
                                                             look_up_algorithm => 1,
172
                                                             auth              => $self);
173
  }
170 174

  
171 175
  $self->set_session_value(login => $params{login}, password => $params{password});
172 176
}
......
177 181
  $self->set_session_value(rpw => SL::Auth::Password->hash_if_unhashed(login => 'root', password => $rpw));
178 182
}
179 183

  
184
sub get_stored_password {
185
  my ($self, $login) = @_;
186

  
187
  my $dbh            = $self->dbconnect;
188

  
189
  return undef unless $dbh;
190

  
191
  my $query             = qq|SELECT password FROM auth."user" WHERE login = ?|;
192
  my ($stored_password) = $dbh->selectrow_array($query, undef, $login);
193

  
194
  return $stored_password;
195
}
196

  
180 197
sub dbconnect {
181 198
  $main::lxdebug->enter_sub(2);
182 199

  
SL/Auth/DB.pm
32 32
  my $login      = shift;
33 33
  my $password   = shift;
34 34

  
35
  my $dbh        = $self->{auth}->dbconnect();
36

  
37
  if (!$dbh) {
38
    $main::lxdebug->leave_sub();
39
    return ERR_BACKEND;
40
  }
41

  
42
  my $query             = qq|SELECT password FROM auth."user" WHERE login = ?|;
43
  my ($stored_password) = $dbh->selectrow_array($query, undef, $login);
35
  my $stored_password = $self->{auth}->get_stored_password($login);
44 36

  
45 37
  my ($algorithm, $algorithm2);
46 38

  
SL/Auth/Password.pm
40 40

  
41 41
  my ($algorithm, $password) = $class->parse($params{password}, 'NONE');
42 42

  
43
  return $algorithm eq 'NONE' ? $class->hash(%params) : $params{password};
43
  return $params{password} unless $algorithm eq 'NONE';
44

  
45
  if ($params{look_up_algorithm}) {
46
    my $stored_password    = $params{auth}->get_stored_password($params{login});
47
    my ($stored_algorithm) = $class->parse($stored_password);
48
    $params{algorithm}     = $stored_algorithm;
49
  }
50

  
51
  return $class->hash(%params);
44 52
}
45 53

  
46 54
sub parse {
sql/Pg-upgrade2-auth/password_hashing.sql
1
-- @tag: password_hashing
2
-- @description: Explicitely set a password hashing algorithm
3
-- @depends:
4
-- @charset: utf-8
5
UPDATE auth."user"
6
  SET password = '{CRYPT}' || password
7
  WHERE NOT (password IS NULL)
8
    AND (password <> '')
9
    AND NOT (password LIKE '{%}%');

Auch abrufbar als: Unified diff