-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.html
76 lines (53 loc) · 1.84 KB
/
password.html
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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>password strength example</title>
<script type="text/javascript" src="./zxcvbn.js"></script>
</head>
<body>
<input type="password" id="password-field" />
<br>
<p id="user-info-text"></p>
<script>
//selector of password-field
let sel_password_field = document.getElementById("password-field");
//selector of user-info
let sel_user_info_field = document.getElementById("user-info-text");
//if selector is valid
if (sel_password_field) {
//add event listener for changes
sel_password_field.addEventListener("keyup", function () {
//read current password
let password = sel_password_field.value;
let result = zxcvbn(password);
console.log(result.score);
let user_info = "extremly unsafe";
switch (result.score) {
case 0:
user_info = "extremly unsafe";
break;
case 1:
user_info = "very unsafe";
break;
case 2:
user_info = "ok";
break;
case 3:
user_info = "good";
break;
case 4:
user_info = "exellent";
break;
default:
user_info = "very unsafe";
break;
}
//update text field
sel_user_info_field.innerHTML = user_info;
})
}
</script>
</body>
</html>