Skip to content

Commit

Permalink
Merge d3a24cb into 44bf0e2
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineOmega committed Oct 31, 2018
2 parents 44bf0e2 + d3a24cb commit bd081f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/PasswordRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public static function changePassword($username, $oldPassword = null)
return $rules;
}

public static function optionallyChangePassword($username, $oldPassword = null)
{
$rules = self::changePassword($username, $oldPassword);

$rules = array_merge($rules, [
'nullable',
]);

foreach ($rules as $key => $rule) {
if (is_string($rule) && $rule === 'required') {
unset($rules[$key]);
}
}

return $rules;
}

public static function login()
{
return [
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/PasswordRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private function getPasswordRuleSets()
PasswordRules::register('username'),
PasswordRules::changePassword('username', 'oldPassword'),
PasswordRules::changePassword('username'),
PasswordRules::optionallyChangePassword('username', 'oldPassword'),
PasswordRules::optionallyChangePassword('username'),
PasswordRules::login(),
];
}
Expand Down

0 comments on commit bd081f0

Please sign in to comment.