PasswordFormatRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 4 1
A message() 0 3 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