Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe85da9

Browse files
password reg moderate
1 parent e125d46 commit fe85da9

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

‎day18/app.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
11
const passwordInput = document.getElementById("password");
22

3-
const passwordLength = document.querySelector("#length");
4-
const selectSymbols = document.querySelector("#symbols");
5-
const selectNumbers = document.querySelector("#numbers");
6-
const selectLowerCase = document.querySelector("#lowercase");
7-
const selectUpperCase = document.querySelector("#uppercase");
8-
const selectSimilar = document.querySelector("#similar");
3+
const passwordLengthElement = document.querySelector("#length");
4+
// const passwordLength = passwordLengthElement.value;
5+
const passwordLengthText = document.querySelector("#lengthText");
6+
7+
const selectSymbols = document.querySelector("#symbols").checked;
8+
const selectNumbers = document.querySelector("#numbers").checked;
9+
const selectLowerCase = document.querySelector("#lowercase").checked;
10+
const selectUpperCase = document.querySelector("#uppercase").checked;
11+
const selectSimilar = document.querySelector("#similar").checked;
912

1013
const newPasswordArr = [];
1114

12-
passwordInput.onkeydown = showSymbol;
15+
// passwordInput.onkeydown = showSymbol;
16+
passwordLengthElement.addEventListener("input", () => showSymbol());
17+
18+
// passwordLength.oninput = () => console.log(passwordLength.value);
1319

14-
function showSymbol(e) {
15-
console.log(getRandomFromChartCode(10, 48));
20+
function showSymbol() {
21+
newPasswordArr.length = 0;
22+
// console.log(passwordLengthElement.value);
1623

17-
// console.log(String.fromCharCode(getRandomNumber()));
24+
for (let i = 0; i <= passwordLengthElement.value; i++) {
25+
if (selectSymbols) {
26+
newPasswordArr.push(getRandomFromChartCode(15, 33));
27+
i++;
28+
}
29+
if (selectNumbers && i <= passwordLengthElement.value) {
30+
newPasswordArr.push(getRandomFromChartCode(10, 48));
31+
i++;
32+
}
33+
if (selectLowerCase && i <= passwordLengthElement.value) {
34+
newPasswordArr.push(getRandomFromChartCode(26, 97));
35+
i++;
36+
}
37+
if (selectUpperCase && i <= passwordLengthElement.value) {
38+
newPasswordArr.push(getRandomFromChartCode(26, 65));
39+
i++;
40+
}
41+
// if (selectSimilar) {
42+
// newPasswordArr.push(getRandomFromChartCode(15, 33));
43+
// i++;
44+
// }
45+
}
46+
47+
passwordInput.value = newPasswordArr.join("");
48+
passwordLengthText.innerHTML = passwordLengthElement.value;
1849
}
1950

51+
// console.log(passwordLengthElement.value);
52+
2053
function getRandomLower() {
2154
return Math.floor(Math.random() * 26) + 97;
2255
} // 26, 97
@@ -31,7 +64,7 @@ function getRandomSymbol() {
3164

3265
function getRandomNumber() {
3366
return Math.floor(Math.random() * 10) + 48;
34-
} // 11, 48
67+
} // 10, 48
3568

3669
function getRandomFromChartCode(quantity, startFrom) {
3770
return String.fromCharCode(Math.floor(Math.random() * quantity) + startFrom);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /