1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Startwind\Inventorio\Util; |
4
|
|
|
|
5
|
|
|
abstract class PasswordUtil |
6
|
|
|
{ |
7
|
|
|
static public function evaluateStrength(string $password): array |
8
|
|
|
{ |
9
|
|
|
$rules = []; |
10
|
|
|
|
11
|
|
|
if (strlen($password) >= 10) { |
12
|
|
|
$rules['passwordTooShort'] = false; |
13
|
|
|
} else { |
14
|
|
|
$rules['passwordTooShort'] = true; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
if (preg_match('/[a-z]/', $password)) { |
18
|
|
|
$rules['noLowercase'] = false; |
19
|
|
|
} else { |
20
|
|
|
$rules['noLowercase'] = true; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if (preg_match('/[A-Z]/', $password)) { |
24
|
|
|
$rules['noUppercase'] = false; |
25
|
|
|
} else { |
26
|
|
|
$rules['noUppercase'] = true; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (preg_match('/[0-9]/', $password)) { |
30
|
|
|
$rules['noNumber'] = false; |
31
|
|
|
} else { |
32
|
|
|
$rules['noNumber'] = true; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (preg_match('/[\W_]/', $password)) { |
36
|
|
|
$rules['noSymbol'] = false; |
37
|
|
|
} else { |
38
|
|
|
$rules['noSymbol'] = true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/* |
42
|
|
|
$types = 0; |
43
|
|
|
$types += preg_match('/[a-z]/', $password); |
44
|
|
|
$types += preg_match('/[A-Z]/', $password); |
45
|
|
|
$types += preg_match('/[0-9]/', $password); |
46
|
|
|
$types += preg_match('/[\W_]/', $password); |
47
|
|
|
if ($types >= 3) { |
48
|
|
|
$score += $variationWeight; |
49
|
|
|
} |
50
|
|
|
*/ |
51
|
|
|
|
52
|
|
|
if (preg_match('/(.)\1{3,}/', $password)) { |
53
|
|
|
$rules['passwordRepeating'] = true; |
54
|
|
|
} else { |
55
|
|
|
$rules['passwordRepeating'] = false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$common = ['123456', 'password', 'qwerty', 'admin', 'letmein']; |
59
|
|
|
if (in_array(strtolower($password), $common)) { |
60
|
|
|
$rules['commonPassword'] = true; |
61
|
|
|
} else { |
62
|
|
|
$rules['commonPassword'] = false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $rules; |
66
|
|
|
} |
67
|
|
|
} |