Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (79 loc) · 2.5 KB
/
Copy pathscript.js
File metadata and controls
103 lines (79 loc) · 2.5 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
const generateBtn = document.querySelector("#generate");
let myLength = 0;
let finalPassword = ""
// Write password to the #password input
function writePassword() {
var passwordLen = getpasswordLength();
var options = getPasswordOptionSet();
var passwordText = document.querySelector("#password");
passwordText.value = makePassword(passwordLen, options);
}
// Add event listener to generate button
generateBtn.addEventListener("click", function (event) {
event.preventDefault()
writePassword()
})
// To get and return the length of the password
function getpasswordLength() {
let passwordLength;
while (true) {
passwordLength = parseInt(prompt("please enter the number of characters that you want for your password. It must be more than 12 characters but less than 128."))
if (isNaN(passwordLength)) {
alert ("The password length must be a number")
}
else {
if (passwordLength < 12 ||passwordLength > 128) {
alert("Password must be between 12 and 128, characters inclusive")
}
else {
break;
}
}
}
return passwordLength
}
// get options for the password from the user and returns ?
function getPasswordOptionSet() {
//Constant values
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const lowerCase = "abcdefghijklmnopqrstuvwxyz"
const numbers = "123456789"
const specialCharacters = "@!#$%&"
//Assigning characters to varable
var numbersInput = confirm("Do you want numbers in your password?");
var lowerCaseInput = confirm("Do you want lowercases in your password?");
var upperCaseInput = confirm("Do you want uppercases in your password?");
var specialCharactersInput = confirm("Do you want special characters in your password?");
// declar a empty string
let options = ""
if (numbersInput) {
options+=numbers
}
if (upperCaseInput) {
options+=upperCase
}
if (lowerCaseInput) {
options+=lowerCase
}
if (specialCharactersInput) {
options+=specialCharacters
}
//finalPassword = makePassword(passwordLength, options)
//console.log(options)
return options
}
// Write password to the #password input
function makePassword(len, options) {
let genPassword = ""
console.log(len)
console.log(options)
for (let i = 0; i < len; i++) {
const randomIndex = Math.floor(Math.random() * options.length)
let randomCharacter = options[randomIndex]
genPassword = genPassword+randomCharacter;
console.log(randomCharacter)
console.log(randomIndex)
}
console.log(genPassword)
return genPassword
}