-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPassword.html
More file actions
179 lines (148 loc) · 5.21 KB
/
Copy pathCheckPassword.html
File metadata and controls
179 lines (148 loc) · 5.21 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Validation</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-align: center;
margin: 50px;
background-color: #f4f4f4;
}
h1 {
color: #333;
}
form {
margin-top: 20px;
}
label {
font-weight: bold;
font-size: 1.2em;
color: #555;
}
input {
padding: 10px;
font-size: 1em;
margin-bottom: 15px;
}
button {
padding: 10px 20px;
font-size: 1em;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
font-size: 1.2em;
margin-top: 20px;
color: #333;
}
#errorMessage {
font-size: 1em;
color: brown;
}
#requirements {
text-align: center;
font-size: 1.2em;
color: #555;
}
#requirements ul {
text-align: left;
list-style-type: none;
padding: 0;
}
</style>
</head>
<body>
<h1>Password Validation</h1>
<form id="passwordForm">
<label for="password">Enter Password:</label><br>
<input type="password" id="password" name="password" required><br>
<button type="button" onclick="validatePassword()">Validate Password</button>
</form>
<p id="result" style="color: brown;text-align: left;margin: unset;"></p>
<div>
<p id="errorMessage" style="margin: inherit;color: brown;text-align: left;"></p>
</div>
<div id="requirements">
<p style="margin: unset;">Password Requirements</p>
<div style="
display: flex;
justify-content: center;
margin: unset;">
<ul style="margin: unset;">
<li>* Length of 8-16 characters.</li>
<li>* Contains letters of the Latin alphabet and at least one digit.</li>
<li>* Does not contain full English words.</li>
</ul>
</div>
</div>
<script>
async function validatePassword() {
document.getElementById("errorMessage").innerHTML = ""; // Reset error message
const password = document.getElementById('password').value;
let errors = [];
try {
validateLength(password, errors);
validateLetters(password, errors);
await validateNoEnglishWord(password, errors);
} catch (error) {
console.error('Error:', error);
}
// Display the result and errors
const resultMessage = errors.length === 0 ? "Password is valid!" : "Password is invalid!";
document.getElementById('result').innerHTML = resultMessage;
if (errors.length > 0) {
const errorMessage = errors.join("<br>");
document.getElementById("errorMessage").innerHTML = errorMessage;
}
}
function validateLength(password, errors) {
if (password.length < 8 || password.length > 16) {
errors.push("The password length is not between 8-16 characters.");
}
}
function validateLetters(password, errors) {
if (!/[0-9]/.test(password) || !/[a-zA-Z]/.test(password)) {
errors.push("The password must contain letters of the Latin alphabet and at least one digit.");
}
}
async function validateNoEnglishWord(password, errors) {
// Fetch the list of English words from the file
const response = await fetch('./wordList.txt');
if (!response.ok) {
errors.push('Network response was not ok');
return;
}
const data = await response.text();
// Split the words into an array
const englishWords = data.split('\n').map(word => word.trim());
const nonLatinRegex = /[^a-zA-Z]/g;
passwordWords = password.split(nonLatinRegex);
passwordWords = passwordWords.filter(Boolean);
if (checkPresentWord(englishWords, passwordWords)) {
errors.push("The password contains a full English word.");
}
// Check if any English word is present in the password
function checkPresentWord(englishWords, passwordWords) {
for (const passwordWord of passwordWords) {
for (const englishWord of englishWords) {
if ((passwordWord.toLowerCase() === englishWord.toLowerCase()) && englishWord.length != 1) {
return true;
break;
}
}
}
return false;
}
}
</script>
</body>
</html>