This repository has been archived by the owner on Feb 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
jquery_strength.js
70 lines (57 loc) · 1.84 KB
/
jquery_strength.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
(function(initializer) {
if (typeof(module) === "object" && module.exports) {
module.exports = initializer;
} else if (typeof(require) === "function" && require.amd) {
require(["password_strength", "jquery"], initializer);
} else {
initializer(window.PasswordStrength, window.jQuery);
}
}(function(PasswordStrength, $){
$.strength = function(username, password, options, callback) {
if (typeof(options) == "function") {
callback = options;
options = {};
} else if (!options) {
options = {};
}
var usernameField = $(username);
var passwordField = $(password);
var strength = new PasswordStrength();
strength.exclude = options["exclude"];
callback = callback || $.strength.callback;
var handler = function(){
strength.username = $(usernameField).val();
if ($(usernameField).length == 0) {
strength.username = username;
}
strength.password = $(passwordField).val();
if ($(passwordField).length == 0) {
strength.password = password;
}
strength.test();
callback(usernameField, passwordField, strength);
};
$(usernameField).keydown(handler);
$(usernameField).keyup(handler);
$(passwordField).keydown(handler);
$(passwordField).keyup(handler);
};
$.extend($.strength, {
callback: function(username, password, strength){
var img = $(password).next("img.strength");
if (!img.length) {
$(password).after("<img class='strength'>");
img = $("img.strength");
}
$(img)
.removeClass("weak")
.removeClass("good")
.removeClass("strong")
.addClass(strength.status)
.attr("src", $.strength[strength.status + "Image"]);
},
weakImage: "/images/weak.png",
goodImage: "/images/good.png",
strongImage: "/images/strong.png"
});
}));