public function PasswordUsername::validate in Password Policy 8.3
Returns a true/false status if the password meets the constraint.
Parameters
string $password: The password entered by the end user.
\Drupal\user\UserInterface: The user which password is changed.
Return value
PasswordPolicyValidation Whether or not the password meets the constraint in the plugin.
Overrides PasswordConstraintInterface::validate
File
- password_policy_username/
src/ Plugin/ PasswordConstraint/ PasswordUsername.php, line 25
Class
- PasswordUsername
- Ensures the password doesn't contain the username.
Namespace
Drupal\password_policy_username\Plugin\PasswordConstraintCode
public function validate($password, UserInterface $user) {
$config = $this
->getConfiguration();
$validation = new PasswordPolicyValidation();
if ($config['disallow_username'] && stripos($password, $user
->getAccountName()) !== FALSE) {
$validation
->setErrorMessage($this
->t('Password must not contain the username.'));
}
return $validation;
}