Skip to content

Commit

Permalink
pkp#3462 Remove user password import function from Validation class
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed May 6, 2018
1 parent 5dc667e commit c391d72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
26 changes: 0 additions & 26 deletions classes/security/Validation.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,30 +433,4 @@ static function canAdminister($administeredUserId, $administratorUserId) {
// There were no conflicting roles. Permit administration.
return true;
}

/**
* Validation process for imported passwords
* @param $userToImport User ByRef. The user that is being imported.
* @param $encryption string null, sha1, md5 (or any other encryption algorithm defined)
* @return string if a new password is generated, the function returns it.
*/
function importUserPasswordValidation(&$userToImport, $encryption) {
$passwordHash = $userToImport->getPassword();
$password = null;
if (!$encryption) {
$userToImport->setPassword(Validation::encryptCredentials($userToImport->getUsername(), $passwordHash));
} else {
if (password_needs_rehash($passwordHash, PASSWORD_BCRYPT)) {

$password = Validation::generatePassword();
$userToImport->setPassword(Validation::encryptCredentials($userToImport->getUsername(), $password));

$userToImport->setMustChangePassword(true);
} else {
$userToImport->setPassword($passwordHash);
}
}

return $password;
}
}
28 changes: 27 additions & 1 deletion plugins/importexport/users/filter/UserXmlPKPUserFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function parseUser($node) {
}

// Password Import Validation
$password = Validation::importUserPasswordValidation($user, $encryption);
$password = $this->importUserPasswordValidation($user, $encryption);

$userByUsername = $userDao->getByUsername($user->getUsername(), false);
$userByEmail = $userDao->getUserByEmail($user->getEmail(), false);
Expand Down Expand Up @@ -220,6 +220,32 @@ function handleChildElement($n) {
fatalError('Unknown element ' . $n->tagName);
}
}

/**
* Validation process for imported passwords
* @param $userToImport User ByRef. The user that is being imported.
* @param $encryption string null, sha1, md5 (or any other encryption algorithm defined)
* @return string if a new password is generated, the function returns it.
*/
function importUserPasswordValidation(&$userToImport, $encryption) {
$passwordHash = $userToImport->getPassword();
$password = null;
if (!$encryption) {
$userToImport->setPassword(Validation::encryptCredentials($userToImport->getUsername(), $passwordHash));
} else {
if (password_needs_rehash($passwordHash, PASSWORD_BCRYPT)) {

$password = Validation::generatePassword();
$userToImport->setPassword(Validation::encryptCredentials($userToImport->getUsername(), $password));

$userToImport->setMustChangePassword(true);
} else {
$userToImport->setPassword($passwordHash);
}
}

return $password;
}
}

?>

0 comments on commit c391d72

Please sign in to comment.