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

PasswordFunctions::isPasswordComplex()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 8
nop 1
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
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
}