1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace PassGenerator;
|
4
|
|
|
|
5
|
|
|
/**
|
6
|
|
|
* The storage for all kinds characters and types string mapping.
|
7
|
|
|
*
|
8
|
|
|
* @author Lachezar Mihaylov <[email protected]>
|
9
|
|
|
* @license https://github.com/lmihaylov2512/pass-generator/blob/master/LICENSE.md MIT License
|
10
|
|
|
*/
|
11
|
|
|
class Storage
|
12
|
|
|
{
|
13
|
|
|
/**
|
14
|
|
|
* @var array list with all allowed characters and their type (type key => characters string pairs)
|
15
|
|
|
*/
|
16
|
|
|
protected static $characters = [
|
17
|
|
|
'upperCase' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
18
|
|
|
'lowerCase' => 'abcdefghijklmnopqrstuvwxyz',
|
19
|
|
|
'digits' => '0123456789',
|
20
|
|
|
'special' => '~!@#$%^&*=+/?.,\|\';:',
|
21
|
|
|
'brackets' => '()[]{}<>',
|
22
|
|
|
'minus' => '-',
|
23
|
|
|
'underline' => '_',
|
24
|
|
|
'space' => ' ',
|
25
|
|
|
];
|
26
|
|
|
|
27
|
|
|
/**
|
28
|
|
|
* Pull and return the array with all characters.
|
29
|
|
|
*
|
30
|
|
|
* @return array the characters list
|
31
|
|
|
*/
|
32
|
|
|
public static function getCharacters(): array
|
33
|
|
|
{
|
34
|
|
|
return static::$characters;
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
/**
|
38
|
|
|
* Return the characters pattern for specific group type.
|
39
|
|
|
*
|
40
|
|
|
* @param string $group passed specific group type
|
41
|
|
|
* @return string the group characters
|
42
|
|
|
*/
|
43
|
|
|
public static function getGroup(string $group): string
|
44
|
|
|
{
|
45
|
|
|
if (array_key_exists($group, static::$characters)) {
|
46
|
|
|
return static::$characters[$group];
|
47
|
|
|
}
|
48
|
|
|
}
|
49
|
|
|
|
50
|
|
|
/**
|
51
|
|
|
* Change characters pattern for specific group.
|
52
|
|
|
*
|
53
|
|
|
* @param string $group specific group
|
54
|
|
|
* @param string $pattern new characters pattern
|
55
|
|
|
* @return void
|
56
|
|
|
*/
|
57
|
|
|
public static function setGroup(string $group, string $pattern)
|
58
|
|
|
{
|
59
|
|
|
if (array_key_exists($group, static::$characters)) {
|
60
|
|
|
static::$characters[$group] = $pattern;
|
61
|
|
|
}
|
62
|
|
|
}
|
63
|
|
|
}
|
64
|
|
|
|