|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the StfalconApiBundle. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Stfalcon LLC <stfalcon.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace StfalconStudio\ApiBundle\Util; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* PasswordRequirementsValidator. |
|
17
|
|
|
*/ |
|
18
|
|
|
class PasswordRequirementsValidator |
|
19
|
|
|
{ |
|
20
|
|
|
private const NUMBER_REGEXP = '/[\d]{1,}/'; |
|
21
|
|
|
private const LOWERCASE_LETTER_REGEXP = '/\p{Ll}{1,}/u'; |
|
22
|
|
|
private const UPPERCASE_LETTER_REGEXP = '/\p{Lu}{1,}/u'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $password |
|
26
|
|
|
* |
|
27
|
|
|
* @return bool |
|
28
|
|
|
*/ |
|
29
|
|
|
public function isValid(string $password): bool |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->hasAtLeastOneNumber($password) |
|
32
|
|
|
&& $this->hasAtLeastOneUnicodeUpperCaseLetter($password) |
|
33
|
|
|
&& $this->hasAtLeastOneUnicodeLowerCaseLetter($password) |
|
34
|
|
|
; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param string $password |
|
39
|
|
|
* |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
|
|
private function hasAtLeastOneNumber(string $password): bool |
|
43
|
|
|
{ |
|
44
|
|
|
return (bool) \preg_match(self::NUMBER_REGEXP, $password); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $password |
|
49
|
|
|
* |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
|
|
private function hasAtLeastOneUnicodeUpperCaseLetter(string $password): bool |
|
53
|
|
|
{ |
|
54
|
|
|
return (bool) \preg_match(self::UPPERCASE_LETTER_REGEXP, $password); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $password |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
|
|
private function hasAtLeastOneUnicodeLowerCaseLetter(string $password): bool |
|
63
|
|
|
{ |
|
64
|
|
|
return (bool) \preg_match(self::LOWERCASE_LETTER_REGEXP, $password); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|