mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9981 from creative-commoners/pull/4.8/blank-password-validation
FIX Ensure changing a password to blank is validated
This commit is contained in:
commit
852268990c
@ -1705,8 +1705,8 @@ class Member extends DataObject
|
||||
$valid = parent::validate();
|
||||
$validator = static::password_validator();
|
||||
|
||||
if (!$this->ID || $this->isChanged('Password')) {
|
||||
if ($this->Password && $validator) {
|
||||
if ($validator) {
|
||||
if ((!$this->ID && $this->Password) || $this->isChanged('Password')) {
|
||||
$userValid = $validator->validate($this->Password, $this);
|
||||
$valid->combineAnd($userValid);
|
||||
}
|
||||
|
@ -53,6 +53,6 @@ class MemberPassword extends DataObject
|
||||
public function checkPassword($password)
|
||||
{
|
||||
$encryptor = PasswordEncryptor::create_for_algorithm($this->PasswordEncryption);
|
||||
return $encryptor->check($this->Password, $password, $this->Salt, $this->Member());
|
||||
return $encryptor->check($this->Password ?? '', $password, $this->Salt, $this->Member());
|
||||
}
|
||||
}
|
||||
|
@ -1601,4 +1601,14 @@ class MemberTest extends FunctionalTest
|
||||
$member->write();
|
||||
$this->assertNotNull(Member::get()->find('Email', 'trimmed@test.com'));
|
||||
}
|
||||
|
||||
public function testChangePasswordToBlankIsValidated()
|
||||
{
|
||||
// override setup() function which setMinLength(0)
|
||||
PasswordValidator::singleton()->setMinLength(8);
|
||||
// 'test' member has a password defined in yml
|
||||
$member = $this->objFromFixture(Member::class, 'test');
|
||||
$result = $member->changePassword('');
|
||||
$this->assertFalse($result->isValid());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user