Skip to content

Instantly share code, notes, and snippets.

@hissy
Created April 9, 2017 07:22
Show Gist options
  • Save hissy/9cd16ec05b0c988a915167df6bd11ded to your computer and use it in GitHub Desktop.
Save hissy/9cd16ec05b0c988a915167df6bd11ded to your computer and use it in GitHub Desktop.
[concrete5] [V8] Add password validation rule
<?php
// application/bootstrap/app.php
/** @var \Concrete\Core\Validator\ValidatorManagerInterface $passwordValidator */
$passwordValidator = Core::make('validator/password');
/** @var \Concrete\Core\Validator\String\RegexValidator $regexValidator */
$regexValidator = Core::make(
\Concrete\Core\Validator\String\RegexValidator::class,
['/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/']
);
$regexValidator->setRequirementString(
\Concrete\Core\Validator\String\RegexValidator::E_DOES_NOT_MATCH,
t('The password must include upper and lower case letters, numbers.')
);
$regexValidator->setErrorString(
\Concrete\Core\Validator\String\RegexValidator::E_DOES_NOT_MATCH,
t('The password must include upper and lower case letters, numbers.')
);
$passwordValidator->setValidator('character_types', $regexValidator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment