-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjavascript.js
88 lines (76 loc) · 2.89 KB
/
javascript.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
document.getElementById('password').addEventListener('input', function() {
var password = this.value;
// Call the function to check password strength and update result
updatePasswordStrength(password);
});
function updatePasswordStrength(password) {
// Implement your password strength checking logic here
// This is a simple example, you can customize it based on your requirements
var strength = 0;
// Check for minimum length
var lengthIndicator = document.getElementById('length-indicator');
if (password.length >= 8) {
strength += 1;
lengthIndicator.innerHTML = '✅ Length';
lengthIndicator.classList.add('valid');
} else {
lengthIndicator.innerHTML = '❌ Length';
lengthIndicator.classList.remove('valid');
}
// Check for the presence of both uppercase and lowercase characters
var caseIndicator = document.getElementById('case-indicator');
if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {
strength += 1;
caseIndicator.innerHTML = '✅ Uppercase & Lowercase';
caseIndicator.classList.add('valid');
} else {
caseIndicator.innerHTML = '❌ Uppercase & Lowercase';
caseIndicator.classList.remove('valid');
}
// Check for the presence of numbers
var numberIndicator = document.getElementById('number-indicator');
if (/\d/.test(password)) {
strength += 1;
numberIndicator.innerHTML = '✅ Number';
numberIndicator.classList.add('valid');
} else {
numberIndicator.innerHTML = '❌ Number';
numberIndicator.classList.remove('valid');
}
// Check for the presence of special characters
var specialCharIndicator = document.getElementById('special-char-indicator');
if (/[^a-zA-Z0-9]/.test(password)) {
strength += 1;
specialCharIndicator.innerHTML = '✅ Special Character';
specialCharIndicator.classList.add('valid');
} else {
specialCharIndicator.innerHTML = '❌ Special Character';
specialCharIndicator.classList.remove('valid');
}
// Update the strength meter UI
var strengthMeter = document.getElementById('strength');
var bars = strengthMeter.getElementsByClassName('bar');
function colorpic(i) {
if (i == 0) {
return '#ff2f00';
} else if (i == 1 ) {
return '#ff9d00';
}
else if (i == 2) {
return '#ffff00';
}
else if (i == 3) {
return '#00ff00';
}
}
for (var i = 0; i < bars.length; i++) {
if (i < strength) {
bars[i].style.backgroundColor = colorpic(i);
} else {
bars[i].style.backgroundColor = 'transparent';
}
}
// Update the result text
var resultElement = document.getElementById('result');
resultElement.innerHTML = `Password Strength: ${strength}/4`;
}