|
11 | 11 | * See the License for the specific language governing permissions and |
12 | 12 | * limitations under the License. |
13 | 13 | **/ |
| 14 | + |
| 15 | +use App\libs\Utils\TextUtils; |
14 | 16 | use Illuminate\Support\Facades\App; |
15 | 17 | use Illuminate\Support\Facades\Config; |
16 | 18 | use Illuminate\Support\Facades\Log; |
17 | 19 | use Illuminate\Support\ServiceProvider; |
18 | 20 | use Illuminate\Support\Facades\Validator; |
| 21 | +use models\exceptions\ValidationException; |
19 | 22 | use Sokil\IsoCodes\IsoCodesFactory; |
20 | 23 | use Validators\CustomValidator; |
21 | 24 | use App\Http\Utils\Log\LaravelMailerHandler; |
@@ -99,12 +102,28 @@ public function boot() |
99 | 102 | }); |
100 | 103 |
|
101 | 104 | Validator::extend("password_policy", function($attribute, $value, $parameters, $validator){ |
102 | | - $min = 8; |
103 | | - $validator->addReplacer('password_policy', function($message, $attribute, $rule, $parameters) use ($validator, $min) { |
104 | | - return sprintf("The %s must be %s–30 characters, and must include a special character", $attribute, $min); |
| 105 | + $password = TextUtils::trim($value); |
| 106 | + |
| 107 | + $min_length = Config::get("auth.password_min_length"); |
| 108 | + if (strlen($password) < $min_length) { |
| 109 | + return false; |
| 110 | + } |
| 111 | + |
| 112 | + $max_length = Config::get("auth.password_max_length"); |
| 113 | + if (strlen($password) > $max_length) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + $warning = Config::get("auth.password_shape_warning"); |
| 117 | + $pattern = Config::get("auth.password_shape_pattern"); |
| 118 | + if (!preg_match("/$pattern/", $password)) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + $validator->addReplacer('password_policy', function($message, $attribute, $rule, $parameters) use ($validator, $min_length, $max_length, $warning) { |
| 123 | + return sprintf("The %s must be %s–%s characters, and %s", $attribute, $min_length, $max_length, $warning); |
105 | 124 | }); |
106 | 125 |
|
107 | | - return preg_match("/^((?=.*?[#?!@()$%^&*=_{}[\]:;\"'|<>,.\/~`±§+-])).{8,30}$/", $value); |
| 126 | + return true; |
108 | 127 | }); |
109 | 128 | } |
110 | 129 |
|
|
0 commit comments