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"];
33 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
36 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
38 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
40 * PwdEmpty: "Please type a password, and then retype it to confirm.",
41 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
42 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
43 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
44 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
45 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
46 * LNInPwd: "Your password can't contain your last name. Please type a different password."
53 * @cfg {String/Object} Label for the strength meter (defaults to
54 * 'Password strength:')
59 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
60 * ['Weak', 'Medium', 'Strong'])
76 initEvents: function () {
77 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
79 if (this.el.is('input[type=password]') && Roo.isSafari) {
80 this.el.on('keydown', this.SafariOnKeyDown, this);
83 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
86 onRender: function (ct, position) {
87 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
88 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
89 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
91 this.trigger.createChild({
94 'margin-bottom': '10px',
99 cls: 'password-meter-grey',
101 //width: this.width + 'px',
107 cls: 'password-meter',
115 if (this.hideTrigger) {
116 this.trigger.setDisplayed(false);
118 this.setSize(this.width || '', this.height || '');
121 onDestroy: function () {
123 this.trigger.removeAllListeners();
124 this.trigger.remove();
129 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
132 checkStrength: function () {
133 var pwd = this.el.getValue();
134 if (pwd == this._lastPwd) {
139 if (this.ClientSideStrongPassword(pwd)) {
141 } else if (this.ClientSideMediumPassword(pwd)) {
143 } else if (this.ClientSideWeakPassword(pwd)) {
148 var pm = this.trigger.child('div/div/div').dom;
149 console.log('strength1: ' + strength);
151 pm.style.width = (this.width / 3) * strength + 'px';
152 //if(this.pwdStrengths != null && strength > 0) {
153 pm.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
155 // pm.innerHTML = '';
161 Roo.bootstrap.SecurePass.superclass.reset.call(this);
163 var pm = this.trigger.child('div/div/div').dom;
168 validateValue: function (value) {
170 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
173 if (value.length == 0) {
174 if (this.allowBlank) {
179 this.markInvalid(this.errors.PwdEmpty);
187 if ('[\x21-\x7e]*'.match(value)) {
188 this.markInvalid(this.errors.PwdBadChar);
191 if (value.length < 6) {
192 this.markInvalid(this.errors.PwdShort);
195 if (value.length > 16) {
196 this.markInvalid(this.errors.PwdLong);
200 if (this.ClientSideStrongPassword(value)) {
202 } else if (this.ClientSideMediumPassword(value)) {
204 } else if (this.ClientSideWeakPassword(value)) {
211 this.markInvalid(this.errors.TooWeak);
214 console.log('strength2: ' + strength);
215 var pm = this.trigger.child('div/div/div').dom;
217 pm.style.width = (this.width / 3) * strength + 'px';
219 pm.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
220 console.log('pm: ' + pm);
222 for (var index = 0; index < this.fieldsFilter.length; ++index) {
223 filter = document.getElementById(this.fieldsFilter[index][0]).value;
226 re = new RegExp(filter);
227 if (re.test(value)) {
228 this.markInvalid(eval('this.errors.'+ this.fieldsFilter[index][1]));
237 CharacterSetChecks: function (type) {
239 this.fResult = false;
242 isctype: function (character, type) {
243 switch (type) { //why needed break after return in js ? very odd bug
244 case this.kCapitalLetter:
245 if (character >= 'A' && character <= 'Z') {
249 case this.kSmallLetter:
250 if (character >= 'a' && character <= 'z') {
255 if (character >= '0' && character <= '9') {
259 case this.kPunctuation:
260 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
270 IsLongEnough: function (pwd, size) {
271 return !(pwd == null || isNaN(size) || pwd.length < size);
274 SpansEnoughCharacterSets: function (word, nb) {
275 if (!this.IsLongEnough(word, nb))
280 var characterSetChecks = new Array(
281 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
282 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation));
283 for (var index = 0; index < word.length; ++index) {
284 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
285 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
286 characterSetChecks[nCharSet].fResult = true;
293 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
294 if (characterSetChecks[nCharSet].fResult) {
299 if (nCharSets < nb) {
305 ClientSideStrongPassword: function (pwd) {
306 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
309 ClientSideMediumPassword: function (pwd) {
310 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
313 ClientSideWeakPassword: function (pwd) {
314 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);