1 | <?php |
||
2 | |||
3 | namespace Validate; |
||
4 | |||
5 | use Exception; |
||
6 | use Validate\Traits\BlockStringTrait; |
||
7 | use Validate\Traits\GetDataTrait; |
||
8 | |||
9 | /** |
||
10 | * I created this validator just to avoid common passwords, you should not use to store passwords. |
||
11 | * Not before you improve that shit! |
||
12 | * |
||
13 | * Criei esse validator apenas para evitar senhas comuns, você não deveria usar para armazenar senhas. |
||
14 | * Não antes de melhorar essa merda! |
||
15 | */ |
||
16 | class Password implements \Validate\Contracts\Validate |
||
17 | { |
||
18 | use BlockStringTrait, GetDataTrait; |
||
19 | |||
20 | /** |
||
21 | * Create hash for store password |
||
22 | * |
||
23 | * @param string $password |
||
24 | * @return string |
||
25 | */ |
||
26 | public static function toDatabase(string $password) |
||
27 | { |
||
28 | return sha256($password); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Never use this function |
||
33 | * |
||
34 | * @param string $password |
||
35 | * @return void |
||
36 | */ |
||
37 | public static function toUser($password) |
||
38 | { |
||
39 | // @todo Nem deveria existir isso aqui ! |
||
40 | die(); |
||
0 ignored issues
–
show
|
|||
41 | return null; |
||
0 ignored issues
–
show
return null is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Verify if client use commoms passwords. |
||
46 | * |
||
47 | * @todo Create validate for password force |
||
48 | * |
||
49 | * @param string $password |
||
50 | * @return boolean |
||
51 | */ |
||
52 | public static function validate(string $password): boolean |
||
0 ignored issues
–
show
The type
Validate\boolean was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
53 | { |
||
54 | if (self::foundInMultiplesArrays( |
||
55 | [ |
||
56 | [ |
||
57 | $password, |
||
58 | self::getListFromFile('black-passwords') |
||
59 | ], |
||
60 | [ |
||
61 | $password, |
||
62 | self::getListFromFile('black-names') |
||
63 | ], |
||
64 | [ |
||
65 | $password, |
||
66 | self::getListFromFile('black-first-names') |
||
67 | ], |
||
68 | ] |
||
69 | ) |
||
70 | ) { |
||
71 | return false; |
||
0 ignored issues
–
show
|
|||
72 | } |
||
73 | |||
74 | return true; |
||
0 ignored issues
–
show
|
|||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Verify |
||
79 | * |
||
80 | * @param string $fromDatabase |
||
81 | * @param string $fromUser |
||
82 | * @return boolean |
||
83 | */ |
||
84 | public static function isSame(string $fromDatabase, string $fromUser) |
||
85 | { |
||
86 | return (self::toDatabase($fromDatabase)===self::toDatabase($fromUser)); |
||
87 | } |
||
88 | |||
89 | public static function generate( |
||
90 | $length = 8, |
||
91 | $keyspace = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%' |
||
92 | ) { |
||
93 | $str = ''; |
||
94 | $max = mb_strlen($keyspace, '8bit') - 1; |
||
95 | if ($max < 1) { |
||
96 | throw new Exception('$keyspace must be at least two characters long'); |
||
97 | } |
||
98 | for ($i = 0; $i < $length; ++$i) { |
||
99 | $str .= $keyspace[random_int(0, $max)]; |
||
100 | } |
||
101 | return $str; |
||
102 | } |
||
103 | } |
||
104 |