PasswordFormatRule::passes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class PasswordFormatRule implements Rule
9
{
10
    /**
11
     * This Password Validation rule should be referenced wherever we need the user input their password on the site.
12
     * The rules used on their passwords are:
13
     * 1) The password is required.
14
     * 2) The password must be at least 9 characters.
15
     * 3) The password may not be greater than 100 characters.
16
     * 4) The password must contain at least one character from the following categories:
17
     * lower-case characters (a-z), upper-case characters (A-Z),
18
     * digits (0-9), and non-alphanumeric symbols (%, $, !, etc.).
19
     * Guide used by Polivas Korop
20
     * https://laraveldaily.com/how-to-create-custom-validation-rules-laravel/
21
     */
22 8
23 8
    public function passes($attribute, $value)
24 8
    {
25
        $passwordPattern = '~^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[.!@#$%^&*]).*$~';
26
        return preg_match($passwordPattern, $value);
27 1
    }
28 1
29
    public function message()
30
    {
31
        return Lang::get('validation.custom.password');
32
    }
33
}
34