forked from neelimagprasad/CitrusHacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.js
112 lines (100 loc) · 3.77 KB
/
password.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
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
104
105
106
107
108
109
110
/* Variable that holds current password to change via input from website */
var x = document.getElementById('pwd').value;
var checker;
var lower = false;
var upper;
var number;
var special;
var length;
var submit = document.getElementById('submit');
var newpass;
/* Code for taking input from website */
document.getElementById('checker').addEventListener("click", function(event){
event.preventDefault();
document.getElementById('passwordChecker').style.display = "block" ;
document.getElementById('buttons').style.display = "none" ;
});
document.getElementById("submit").addEventListener("click", function(event){
event.preventDefault();
x = document.getElementById('pwd').value;
newpass = x
checker = /[a-z]/;
lower = checker.test(x);
checker = /[A-Z]/;
upper = checker.test(x);
checker = /[0-9]/;
number = checker.test(x);
checker = /[!@#$%^&*]/;
special = checker.test(x);
length = x.length;
if(lower == false){
document.getElementById('message_lower').style.display= 'block';
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var randletter = alphabet[Math.floor(Math.random() * alphabet.length)];
newpass += randletter;
}
else{
document.getElementById('message_lower').style.display= 'none';
}
if(upper == false){
document.getElementById('message_upper').style.display= 'block';
var Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var randletter2 = Alphabet[Math.floor(Math.random() * Alphabet.length)];
newpass += randletter2;
}
else{
document.getElementById('message_upper').style.display= 'none';
}
if(number == false){
document.getElementById('message_number').style.display= 'block';
var nums = "0123456789";
var randnum = nums[Math.floor(Math.random() * nums.length)];
newpass += randnum;
}
else{
document.getElementById('message_number').style.display= 'none';
}
if(special == false){
document.getElementById('message_special').style.display= 'block';
var specialchars = "!@#$%^&*";
var randchar = specialchars[Math.floor(Math.random() * specialchars.length)];
newpass += randchar;
}
else{
document.getElementById('message_special').style.display= 'none';
}
if(length < 10){
document.getElementById('message_length').style.display= 'block';
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*";
while (newpass.length < 10) {
newpass += chars[Math.floor(Math.random() * chars.length)];;
}
}
else{
document.getElementById('message_length').style.display= 'none';
}
if(lower == true && upper == true && number == true && special == true && length >7){
document.getElementById('message_good').style.display= 'block';
}
else{
document.getElementById('message_good').style.display= 'block';
}
if(newpass != x){
document.getElementById("suggestions").innerHTML = newpass;
document.getElementById('email_box').style.display= 'block';
}
else{
document.getElementById('email_box').style.display= 'none';
}
});
document.getElementById("submit1").addEventListener("click", function(event){
event.preventDefault();
document.getElementById('linkshow').style.display= 'block';
var email = document.getElementById('email').value;
var string = "mailto:"+email+"?subject= Secure Password&body= Your new password is "+newpass;
console.log(email);
console.log(string);
var link = document.getElementById("send");
link.innerHTML = "email";
link.setAttribute('href', "mailto:"+email+"?subject= Secure Password&body= Your new password is "+newpass);
});