/
mod.ts
61 lines (56 loc) 路 1.23 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
interface IParams {
password: string;
minLen?: number;
maxLen?: number;
containsNum?: boolean;
containsSpecialChar?: boolean;
containsAlphabet?: boolean;
checkWithCommonPasswords?: boolean;
}
const url =
"https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10k-most-common.txt";
const response = await fetch(
url,
);
const passwordList = await response.text();
export function checkPassword({
password,
minLen = 0,
maxLen = 0,
containsNum = true,
containsSpecialChar = true,
containsAlphabet = true,
checkWithCommonPasswords = false,
}: IParams): boolean {
if (minLen != 0) {
if (password.length < minLen) {
return false;
}
}
if (maxLen != 0) {
if (password.length > maxLen) {
return false;
}
}
if (containsNum) {
if (password.search(/\d/) == -1) {
return false;
}
}
if (containsSpecialChar) {
if (password.search(/[^\w\s]/) == -1) {
return false;
}
}
if (containsAlphabet) {
if (password.search(/[A-Za-z]/) == -1) {
return false;
}
}
if (checkWithCommonPasswords) {
if (passwordList != undefined && passwordList.includes(password)) {
return false;
}
}
return true;
}