1
1
const passwordInput = document . getElementById ( "password" ) ;
2
2
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 ;
9
12
10
13
const newPasswordArr = [ ] ;
11
14
12
- passwordInput . onkeydown = showSymbol ;
15
+ // passwordInput.onkeydown = showSymbol;
16
+ passwordLengthElement . addEventListener ( "input" , ( ) => showSymbol ( ) ) ;
17
+
18
+ // passwordLength.oninput = () => console.log(passwordLength.value);
13
19
14
- function showSymbol ( e ) {
15
- console . log ( getRandomFromChartCode ( 10 , 48 ) ) ;
20
+ function showSymbol ( ) {
21
+ newPasswordArr . length = 0 ;
22
+ // console.log(passwordLengthElement.value);
16
23
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 ;
18
49
}
19
50
51
+ // console.log(passwordLengthElement.value);
52
+
20
53
function getRandomLower ( ) {
21
54
return Math . floor ( Math . random ( ) * 26 ) + 97 ;
22
55
} // 26, 97
@@ -31,7 +64,7 @@ function getRandomSymbol() {
31
64
32
65
function getRandomNumber ( ) {
33
66
return Math . floor ( Math . random ( ) * 10 ) + 48 ;
34
- } // 11 , 48
67
+ } // 10 , 48
35
68
36
69
function getRandomFromChartCode ( quantity , startFrom ) {
37
70
return String . fromCharCode ( Math . floor ( Math . random ( ) * quantity ) + startFrom ) ;
0 commit comments