-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (47 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
59 lines (47 loc) · 1.69 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
var abcUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var abcUpperArr = abcUpper.split("");
var abcLower = "abcdefghijklmnopqrstuvwxyz";
var abcLowerArr = abcLower.split("");
var num = "0123456789";
var numArr = num.split("");
var sym = "!#$%&\()*+,-./:;<=>?@^[\\]^_`{|}~";
var symArr = sym.split("");
function generatePassword() {
var allChars = [];
var resultPass = "";
var totlength = prompt("How many characters would you like your password to be?");
if (confirm("Would you like your password to contain upper case letters?")) {
Array.prototype.push.apply(allChars, abcUpperArr);
}
if (confirm("Would you like your password to contain lower case letters?")) {
Array.prototype.push.apply(allChars, abcLowerArr);
}
if (confirm("Would you like your password to contain numbers?")) {
Array.prototype.push.apply(allChars, numArr);
}
if (confirm("Would you like your password to contain symbols?")) {
Array.prototype.push.apply(allChars, symArr);
}
if (allChars.length === 0) {
alert("You must select at lease 1 type of characters to generate a password!\nPlease start over.");
}
else {
for (var i = 0; i < totlength; i++) {
var random = Math.floor(Math.random() * allChars.length);
resultPass += allChars[random];
}
}
document.getElementById("password").innerHTML = resultPass;
};
function copyPassword() {
document.querySelector("textarea").select();
password = $("#password").html();
if (password !== "") {
document.execCommand("Copy");
alert("Password copied to clipboard!");
}
else
{
alert("Please Generate Password First !");
}
};