9 * @class Roo.bootstrap.SecurePass
10 * @extends Roo.bootstrap.Input
11 * Bootstrap SecurePass class
15 * Create a new SecurePass
16 * @param {Object} config The config object
19 Roo.bootstrap.SecurePass = function (config) {
20 // these go here, so the translation tool can replace them..
22 PwdEmpty: "Please type a password, and then retype it to confirm.",
23 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
24 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
25 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
26 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
27 FNInPwd: "Your password can't contain your first name. Please type a different password.",
28 LNInPwd: "Your password can't contain your last name. Please type a different password.",
29 TooWeak: "Your password is Too Weak."
31 this.meterLabel = "Password strength:";
32 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
34 "roo-password-meter-tooweak",
35 "roo-password-meter-weak",
36 "roo-password-meter-medium",
37 "roo-password-meter-strong",
38 "roo-password-meter-grey"
43 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
46 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
48 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
50 * PwdEmpty: "Please type a password, and then retype it to confirm.",
51 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
52 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
53 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
54 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
55 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
56 * LNInPwd: "Your password can't contain your last name. Please type a different password."
66 * @cfg {String/Object} Label for the strength meter (defaults to
67 * 'Password strength:')
72 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
73 * ['Weak', 'Medium', 'Strong'])
89 initEvents: function ()
91 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
93 if (this.el.is('input[type=password]') && Roo.isSafari) {
94 this.el.on('keydown', this.SafariOnKeyDown, this);
97 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
100 onRender: function (ct, position)
102 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
103 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
104 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
106 this.trigger.createChild({
111 cls: 'roo-password-meter-grey col-xs-12',
114 //width: this.meterWidth + 'px'
118 cls: 'roo-password-meter-text'
124 if (this.hideTrigger) {
125 this.trigger.setDisplayed(false);
127 this.setSize(this.width || '', this.height || '');
130 onDestroy: function ()
133 this.trigger.removeAllListeners();
134 this.trigger.remove();
139 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
142 checkStrength: function ()
144 var pwd = this.inputEl().getValue();
145 if (pwd == this._lastPwd) {
150 if (this.ClientSideStrongPassword(pwd)) {
152 } else if (this.ClientSideMediumPassword(pwd)) {
154 } else if (this.ClientSideWeakPassword(pwd)) {
160 Roo.log('strength1: ' + strength);
162 //var pm = this.trigger.child('div/div/div').dom;
163 var pm = this.trigger.child('div/div');
164 pm.removeClass(this.meterClass);
165 pm.addClass(this.meterClass[strength]);
168 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
170 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
175 Roo.bootstrap.SecurePass.superclass.reset.call(this);
179 var pm = this.trigger.child('div/div');
180 pm.removeClass(this.meterClass);
181 pm.addClass('roo-password-meter-grey');
184 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
187 this.inputEl().dom.type='password';
190 validateValue: function (value) {
192 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
195 if (value.length == 0) {
196 if (this.allowBlank) {
201 this.markInvalid(this.errors.PwdEmpty);
202 this.errorMsg = this.errors.PwdEmpty;
210 if ('[\x21-\x7e]*'.match(value)) {
211 this.markInvalid(this.errors.PwdBadChar);
212 this.errorMsg = this.errors.PwdBadChar;
215 if (value.length < 6) {
216 this.markInvalid(this.errors.PwdShort);
217 this.errorMsg = this.errors.PwdShort;
220 if (value.length > 16) {
221 this.markInvalid(this.errors.PwdLong);
222 this.errorMsg = this.errors.PwdLong;
226 if (this.ClientSideStrongPassword(value)) {
228 } else if (this.ClientSideMediumPassword(value)) {
230 } else if (this.ClientSideWeakPassword(value)) {
238 //this.markInvalid(this.errors.TooWeak);
239 this.errorMsg = this.errors.TooWeak;
244 console.log('strength2: ' + strength);
246 //var pm = this.trigger.child('div/div/div').dom;
248 var pm = this.trigger.child('div/div');
249 pm.removeClass(this.meterClass);
250 pm.addClass(this.meterClass[strength]);
252 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
254 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
260 CharacterSetChecks: function (type) {
262 this.fResult = false;
265 isctype: function (character, type) {
266 switch (type) { //why needed break after return in js ? very odd bug
267 case this.kCapitalLetter:
268 if (character >= 'A' && character <= 'Z') {
272 case this.kSmallLetter:
273 if (character >= 'a' && character <= 'z') {
278 if (character >= '0' && character <= '9') {
282 case this.kPunctuation:
283 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
293 IsLongEnough: function (pwd, size) {
294 return !(pwd == null || isNaN(size) || pwd.length < size);
297 SpansEnoughCharacterSets: function (word, nb) {
298 if (!this.IsLongEnough(word, nb))
303 var characterSetChecks = new Array(
304 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
305 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation));
306 for (var index = 0; index < word.length; ++index) {
307 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
308 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
309 characterSetChecks[nCharSet].fResult = true;
316 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
317 if (characterSetChecks[nCharSet].fResult) {
322 if (nCharSets < nb) {
328 ClientSideStrongPassword: function (pwd) {
329 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
332 ClientSideMediumPassword: function (pwd) {
333 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
336 ClientSideWeakPassword: function (pwd) {
337 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);