]>
git.ipfire.org Git - ipfire.org.git/blob - src/templates/people/modules/password.js
2 var progress
= $("#password-strength");
3 var warning
= $("#password-warning");
4 var feedback
= $("#password-feedback");
6 var password1
= $("#password1");
7 var password2
= $("#password2");
9 var form
= password1
.parents("form");
10 var submit
= form
.find(":submit");
12 // Fetch words that are common to the user
13 var user_inputs
= password1
.data("user-input").split(" ");
17 password1
.keyup(function(event
) {
18 var val1
= password1
.val();
21 // Estimate password quality
22 quality
= zxcvbn(val1
, user_inputs
);
24 // Convert score into percentage
25 var percentage
= (quality
.score
+ 1) * 20;
27 // Set progress bar width
28 progress
.css("width", percentage
+ "%");
30 // Clear all previous backgrounds
31 progress
.removeClass([
32 "bg-success", "bg-warning", "bg-danger"
35 // Make progress bar show in the right colour
36 switch (quality
.score
) {
40 progress
.addClass("bg-danger");
44 progress
.addClass("bg-warning");
48 progress
.addClass("bg-success");
56 if (quality
.feedback
) {
57 if (quality
.feedback
.warning
) {
58 warning
.html(quality
.feedback
.warning
);
61 $.each(quality
.feedback
.suggestions
, function (i
, suggestion
) {
62 feedback
.append("<li>" + suggestion
+ "</li>");
66 progress
.css("width", "0%");
73 form
.trigger("change");
76 password2
.keyup(function(event
) {
77 form
.trigger("change");
80 form
.on("change", function() {
81 $("#password-mismatch").hide();
82 submit
.prop("disabled", true);
84 var val1
= password1
.val();
85 var val2
= password2
.val();
87 // We cannot submit the form when password2 is empty
91 // If the passwords match, we allow to submit the form
93 $("#password-mismatch").show();
97 if (!quality
|| quality
.score
< 3)
100 // They match, so we can enable the submit button
101 submit
.prop("disabled", false);