Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
weakpassword.php
1
<?php
2
10
namespace
Bitrix\Main\Authentication\Policy
;
11
12
use
Bitrix\Main\IO
;
13
14
class
WeakPassword
15
{
16
public
const
MIN_PASSWORD_LENGTH
= 6;
17
25
public
static
function
createIndex
(
string
$dataFile,
string
$path): bool
26
{
27
$file =
new
IO\File
($dataFile);
28
29
$passwords = $file->getContents();
30
31
$passwords = str_replace([
"\r\n"
,
"\r"
],
"\n"
, $passwords);
32
$passwords = explode(
"\n"
, $passwords);
33
34
$hashedPasswords = [];
35
foreach
($passwords as $password)
36
{
37
if
(strlen($password) >= self::MIN_PASSWORD_LENGTH)
38
{
39
$hash = md5($password);
40
$name = $hash[0] . $hash[1];
// 256 possible keys
41
$hashedPasswords[$name][] = (string)$password;
42
}
43
}
44
unset($passwords);
45
46
foreach
($hashedPasswords as $name => $value)
47
{
48
// we need the first and the last \n as a search pattern separator
49
$content =
"\n"
. implode(
"\n"
, $value) .
"\n"
;
50
51
$indexFile =
new
IO\File
($path .
'/'
. $name .
'.txt'
);
52
53
if
($indexFile->putContents($content) ===
false
)
54
{
55
return
false
;
56
}
57
}
58
59
return
true
;
60
}
61
69
public
static
function
exists
(
string
$password,
string
$path): bool
70
{
71
$hash = md5($password);
72
$name = $hash[0] . $hash[1];
73
74
$indexFile =
new
IO\File
($path .
'/'
. $name .
'.txt'
);
75
76
if
(!$indexFile->isExists())
77
{
78
return
false
;
79
}
80
81
$passwords = $indexFile->getContents();
82
83
return
(strpos($passwords,
"\n"
. $password .
"\n"
) !==
false
);
84
}
85
}
Bitrix\Main\Authentication\Policy\WeakPassword
Definition
weakpassword.php:15
Bitrix\Main\Authentication\Policy\WeakPassword\MIN_PASSWORD_LENGTH
const MIN_PASSWORD_LENGTH
Definition
weakpassword.php:16
Bitrix\Main\Authentication\Policy\WeakPassword\exists
static exists(string $password, string $path)
Definition
weakpassword.php:69
Bitrix\Main\Authentication\Policy\WeakPassword\createIndex
static createIndex(string $dataFile, string $path)
Definition
weakpassword.php:25
Bitrix\Main\IO\File
Definition
file.php:7
Bitrix\Main\Authentication\Policy
Definition
booleanrule.php:10
Bitrix\Main\IO
Definition
directory.php:2
modules
main
lib
authentication
policy
weakpassword.php
Создано системой
1.10.0