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