-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (33 loc) · 1.37 KB
/
script.js
File metadata and controls
49 lines (33 loc) · 1.37 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
//generate random password
function generate(){
//set password length/complexity
let complexity = document.getElementById("slider").value;
//possible password values
let values = "ABCDEFGHIJKLMNOPQRSTUVWZYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_+";
let password = "";
//create for loop to choose password characters
for(var i = 0; i <= complexity; i++){
password = password + values.charAt(Math.floor(Math.random() * Math.floor(values.length - 1)));
}
//add password to textbox/display area
document.getElementById("display").value = password;
//add password to previously generated passwords section
document.getElementById("lastNums").innerHTML += password + "<br />";
}
//set default length display of 25
document.getElementById("length").innerHTML = "Length: 25";
//function to set length based on slider position
document.getElementById("slider").oninput = function(){
if(document.getElementById("slider").value > 0){
document.getElementById("length").innerHTML = "Length: " + document.getElementById("slider").value;
}
else{
document.getElementById("length").innerHTML = "Length: 1";
}
}
//function to copy password to clipboard
function copyPassword(){
document.getElementById("display").select();
document.execCommand("Copy");
alert("Password copied to clipboard!");
}