'Prepend salt' toggle
This commit is contained in:
@@ -297,9 +297,7 @@ final class UserBackend extends ABackend implements
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($user->salt !== null) {
|
||||
$password .= $user->salt;
|
||||
}
|
||||
$password = $this->addSalt($user, $password);
|
||||
|
||||
$isCorrect = $passwordAlgorithm->checkPassword(
|
||||
$password, $user->password
|
||||
@@ -350,6 +348,27 @@ final class UserBackend extends ABackend implements
|
||||
return $passwordAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append or prepend salt from external column if available.
|
||||
*
|
||||
* @param User $user The user instance.
|
||||
* @param string $password The password.
|
||||
*
|
||||
* @return string Salted password.
|
||||
*/
|
||||
private function addSalt(User $user, string $password): string
|
||||
{
|
||||
if ($user->salt !== null) {
|
||||
if (empty($this->properties[Opt::PREPEND_SALT])) {
|
||||
return $password . $user->salt;
|
||||
} else {
|
||||
return $user->salt . $password;
|
||||
}
|
||||
}
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -457,9 +476,7 @@ final class UserBackend extends ABackend implements
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($user->salt !== null) {
|
||||
$password .= $user->salt;
|
||||
}
|
||||
$password = $this->addSalt($user, $password);
|
||||
|
||||
$passwordHash = $passwordAlgorithm->getPasswordHash($password);
|
||||
if ($passwordHash === false) {
|
||||
|
||||
@@ -34,6 +34,7 @@ final class Opt
|
||||
const HOME_MODE = "opt.home_mode";
|
||||
const NAME_CHANGE = "opt.name_change";
|
||||
const PASSWORD_CHANGE = "opt.password_change";
|
||||
const PREPEND_SALT = "opt.prepend_salt";
|
||||
const QUOTA_SYNC = "opt.quota_sync";
|
||||
const USE_CACHE = "opt.use_cache";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user