'Prepend salt' toggle

This commit is contained in:
Marcin Łojewski
2018-09-30 20:36:58 +02:00
parent f0d3d170f3
commit 2ef7716527
5 changed files with 28 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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";
}