Completed
Push — master ( a7b0c2...fe24f6 )
by Wanderson
02:20
created

Password::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Authentication;
4
5
/**
6
 * Auxilia manipular senhas
7
 */
8
abstract class Password {
9
10
	private static $salt = 'E50H%gDui#';
11
12
	/**
13
	 * Retorna uma senha aleatoria
14
	 * A senha tem sempre pelo menos: 1 caracter especial e 2 numeros;
15
	 * @param int $length
16
	 * @return string
17
	 */
18
	public static function generate($length = 6) {
19
		$letters = str_shuffle('abcdefghijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXY');
20
		$numbers = str_shuffle('23456789');
21
		$specials = str_shuffle('@#&');
22
23
		$password = substr($letters, 0, $length - 3)
24
				. substr($numbers, 0, 2)
25
				. substr($specials, 0, 1);
26
27
		return str_shuffle($password);
28
	}
29
30
	/**
31
	 * Adiciona maior segurança a senha
32
	 * @param string $password
33
	 */
34
	public static function encrypt($password) {
35
		return md5($password . static::$salt);
0 ignored issues
show
Bug introduced by
Since $salt is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $salt to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
36
	}
37
38
}
39