sub store_credentials_in_session {
my ($self, %params) = @_;
- $params{password} = SL::Auth::Password->hash_if_unhashed(login => $params{login}, password => $params{password})
- unless $self->{authenticator}->requires_cleartext_password;
+ if (!$self->{authenticator}->requires_cleartext_password) {
+ $params{password} = SL::Auth::Password->hash_if_unhashed(login => $params{login},
+ password => $params{password},
+ look_up_algorithm => 1,
+ auth => $self);
+ }
$self->set_session_value(login => $params{login}, password => $params{password});
}
$self->set_session_value(rpw => SL::Auth::Password->hash_if_unhashed(login => 'root', password => $rpw));
}
+sub get_stored_password {
+ my ($self, $login) = @_;
+
+ my $dbh = $self->dbconnect;
+
+ return undef unless $dbh;
+
+ my $query = qq|SELECT password FROM auth."user" WHERE login = ?|;
+ my ($stored_password) = $dbh->selectrow_array($query, undef, $login);
+
+ return $stored_password;
+}
+
sub dbconnect {
$main::lxdebug->enter_sub(2);
my $login = shift;
my $password = shift;
- my $dbh = $self->{auth}->dbconnect();
-
- if (!$dbh) {
- $main::lxdebug->leave_sub();
- return ERR_BACKEND;
- }
-
- my $query = qq|SELECT password FROM auth."user" WHERE login = ?|;
- my ($stored_password) = $dbh->selectrow_array($query, undef, $login);
+ my $stored_password = $self->{auth}->get_stored_password($login);
my ($algorithm, $algorithm2);
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 {
--- /dev/null
+-- @tag: password_hashing
+-- @description: Explicitely set a password hashing algorithm
+-- @depends:
+-- @charset: utf-8
+UPDATE auth."user"
+ SET password = '{CRYPT}' || password
+ WHERE NOT (password IS NULL)
+ AND (password <> '')
+ AND NOT (password LIKE '{%}%');