Passed
Push — master ( 7c7732...5d308c )
by Stone
03:35
created

PasswordFunctions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A isPasswordComplex() 0 22 4
1
<?php
2
3
namespace Core\Traits;
4
5
trait PasswordFunctions
6
{
7
    public function isPasswordComplex(string $password):array
8
    {
9
        $errors = array();
10
        $errors["success"] = true;
11
        $errors["message"] = null;
12
13
        if (strlen($password) < 8) {
14
            $errors["success"] = false;
15
            $errors["message"] = "Password too short!";
16
        }
17
18
        if (!preg_match("#[0-9]+#", $password)) {
19
            $errors["success"] = false;
20
            $errors["message"] = "Password must include at least one number!";
21
        }
22
23
        if (!preg_match("#[a-zA-Z]+#", $password)) {
24
            $errors["success"] = false;
25
            $errors["message"] = "Password must include at least one letter!";
26
        }
27
28
        return $errors;
29
    }
30
}