|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 05.04.2018 |
|
25
|
|
|
* Time: 22:01 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class Validator_Password implements Validator_Base { |
|
29
|
|
|
|
|
30
|
|
|
public function isValide($value): bool { |
|
31
|
|
|
$valide = true; |
|
32
|
|
|
|
|
33
|
|
|
//throw event, so plugins like pwned can interact |
|
34
|
|
|
Events::throwEvent("validate_password", array( |
|
35
|
|
|
'password' => &$value, |
|
36
|
|
|
'valide' => &$valide |
|
37
|
|
|
)); |
|
38
|
|
|
|
|
39
|
|
|
if (!$valide) { |
|
|
|
|
|
|
40
|
|
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (strlen($value) < Settings::get("password_min_length", 6)) { |
|
44
|
|
|
return false; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (strlen($value) > Settings::get("password_max_length", 64)) { |
|
48
|
|
|
//more than 64 characters arent supported |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
//everything is allowed |
|
53
|
|
|
return true; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function validate($value) { |
|
57
|
|
|
if ($this->isValide($value)) { |
|
58
|
|
|
return $value; |
|
59
|
|
|
} else { |
|
60
|
|
|
throw new SecurityException("password is not valide!"); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function get (string $value) : string { |
|
65
|
|
|
$obj = new Validator_Password(); |
|
66
|
|
|
return $obj->validate($value); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
?> |
|
|
|
|
|
|
72
|
|
|
|