2018-04-29 22:53:46 +02:00
|
|
|
<?php
|
|
|
|
|
2021-03-22 10:28:28 +01:00
|
|
|
class ValidatePasswordTest extends \PHPUnit\Framework\TestCase
|
|
|
|
{
|
2021-04-13 22:19:16 +02:00
|
|
|
public function testBasic()
|
|
|
|
{
|
2018-04-29 22:53:46 +02:00
|
|
|
$config = Config::getInstance();
|
|
|
|
|
2018-05-02 13:54:17 +02:00
|
|
|
// Set to the defaults, just to make sure.
|
2018-04-29 22:53:46 +02:00
|
|
|
Config::write('password_validation', array(
|
2022-02-13 18:21:20 +01:00
|
|
|
# '/regular expression/' => '$PALANG key (optional: + parameter)',
|
2018-04-29 22:53:46 +02:00
|
|
|
'/.{5}/' => 'password_too_short 5', # minimum length 5 characters
|
|
|
|
'/([a-zA-Z].*){3}/' => 'password_no_characters 3', # must contain at least 3 characters
|
|
|
|
'/([0-9].*){2}/' => 'password_no_digits 2', # must contain at least 2 digits
|
2022-02-13 18:21:20 +01:00
|
|
|
# '/([!\".,*&^%$£)(_+=\-`\'#@~\[\]\\<>\/].*){1}/' => 'password_no_special 1', # must contain at least 1 special character
|
2018-04-29 22:53:46 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEmpty(validate_password('fishSheep01'));
|
|
|
|
$this->assertEmpty(validate_password('Password01'));
|
|
|
|
$this->assertNotEmpty(validate_password('pas')); // notEmpty == fail
|
|
|
|
$this->assertNotEmpty(validate_password('pa1'));
|
|
|
|
}
|
2022-02-13 18:21:20 +01:00
|
|
|
|
|
|
|
public function testSpecial()
|
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
|
|
|
|
// Set to the defaults, just to make sure.
|
|
|
|
Config::write('password_validation', array(
|
2022-02-13 21:32:39 +01:00
|
|
|
'/([!\".,*&^%$£)(_+=\-`\'#@~\[\]\\<>\/].*){1,}/' => 'password_no_special 1', # must contain at least 1 special character
|
2022-02-13 18:21:20 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEmpty(validate_password('fish^Sh$$p01'));
|
|
|
|
$this->assertEmpty(validate_password(']/>'));
|
2022-02-13 21:32:39 +01:00
|
|
|
$this->assertEmpty(validate_password("P'55w\\ord"));
|
|
|
|
$this->assertEmpty(validate_password("P'55word"), "should contain 1 special char");
|
|
|
|
$this->assertNotEmpty(validate_password("fishSheep01"), "does not contain any special chars...");
|
2022-02-13 18:21:20 +01:00
|
|
|
}
|
2018-04-29 22:53:46 +02:00
|
|
|
}
|