-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (39 loc) · 1.39 KB
/
script.js
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
// Show Slider Value
let slider = document.getElementById("passwordRange");
let output = document.getElementById("sliderNum");
output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function () {
output.innerHTML = this.value;
};
// Copy On Click
function copyOnClick() {
// Get the text field
let copyPassword = document.getElementById("passwordOut");
// Select the text field
copyPassword.select();
copyPassword.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
navigator.clipboard.writeText(copyPassword.value);
}
// All of cause of Prettier
const alphabetLower = "abcdefghijklmnopqrstuvwxyz";
const alphabetUpper = alphabetLower.toUpperCase();
const numbers = "1234567890";
const symbols = "~`!@#$%^&*()_-+={[}],|:;<>.?/";
// ------------------------------------------------
let characters = alphabetUpper + alphabetLower + numbers + symbols;
//Generates the password
function generatePassword() {
let passwordlength = slider.value;
let password = "";
// Displays it
let text = document.getElementById("passwordOut");
for (let i = 1; i <= passwordlength; i++) {
let char = Math.floor(Math.random() * characters.length + 1);
password += characters.charAt(char);
}
// Displays it
text.value = password;
return password;
}