9 * @class Roo.bootstrap.form.SecurePass
10 * @extends Roo.bootstrap.form.Input
11 * Bootstrap SecurePass class
12 * @cfg {Number} minimumStrength invalid if the strength of the password input is less than the minimum strength (from 0 to 3) (default 2)
16 * Create a new SecurePass
17 * @param {Object} config The config object
20 Roo.bootstrap.form.SecurePass = function (config) {
22 Roo.bootstrap.form.SecurePass.superclass.constructor.call(this, config);
25 Roo.extend(Roo.bootstrap.form.SecurePass, Roo.bootstrap.form.Input, {
42 initEvents: function ()
44 Roo.bootstrap.form.SecurePass.superclass.initEvents.call(this);
46 if (this.el.is('input[type=password]') && Roo.isSafari) {
47 this.el.on('keydown', this.SafariOnKeyDown, this);
50 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
53 onRender: function (ct, position)
55 Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
56 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
57 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
59 this.trigger.createChild({
64 cls: 'roo-password-meter-grey col-xs-12',
67 //width: this.meterWidth + 'px'
71 cls: 'roo-password-meter-text'
77 if (this.hideTrigger) {
78 this.trigger.setDisplayed(false);
80 this.setSize(this.width || '', this.height || '');
83 onDestroy: function ()
86 this.trigger.removeAllListeners();
87 this.trigger.remove();
92 Roo.bootstrap.form.TriggerField.superclass.onDestroy.call(this);
95 checkStrength: function ()
97 var pwd = this.inputEl().getValue();
98 if (pwd == this._lastPwd) {
103 if (this.ClientSideStrongPassword(pwd)) {
105 } else if (this.ClientSideMediumPassword(pwd)) {
107 } else if (this.ClientSideWeakPassword(pwd)) {
113 Roo.log('strength1: ' + strength);
115 //var pm = this.trigger.child('div/div/div').dom;
116 var pm = this.trigger.child('div/div');
117 pm.removeClass(Roo.bootstrap.form.SecurePass.meterClass);
118 pm.addClass(Roo.bootstrap.form.SecurePass.meterClass[strength]);
121 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
123 pt.innerHTML = Roo.bootstrap.form.SecurePass.meterLabel + ' ' + Roo.bootstrap.form.SecurePass.pwdStrengths[strength];
129 Roo.bootstrap.form.SecurePass.superclass.reset.call(this);
133 var pm = this.trigger.child('div/div');
134 pm.removeClass(Roo.bootstrap.form.SecurePass.meterClass);
135 pm.addClass('roo-password-meter-grey');
138 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
141 this.inputEl().dom.type='password';
144 validateValue: function (value)
146 if (!Roo.bootstrap.form.SecurePass.superclass.validateValue.call(this, value)) {
149 if (value.length == 0) {
150 if (this.allowBlank) {
155 this.invalidText = Roo.bootstrap.form.SecurePass.errors.PwdEmpty;
163 if (!value.match(/[\x21-\x7e]+/)) {
164 this.invalidText = Roo.bootstrap.form.SecurePass.errors.PwdBadChar;
167 if (value.length < 6) {
168 this.invalidText = Roo.bootstrap.form.SecurePass.errors.PwdShort;
171 if (value.length > 16) {
172 this.invalidText = Roo.bootstrap.form.SecurePass.errors.PwdLong;
176 if (this.ClientSideStrongPassword(value)) {
178 } else if (this.ClientSideMediumPassword(value)) {
180 } else if (this.ClientSideWeakPassword(value)) {
187 if (strength < this.minimumStrength) {
188 this.invalidText = Roo.bootstrap.form.SecurePass.errors.TooWeak;
193 console.log('strength2: ' + strength);
195 //var pm = this.trigger.child('div/div/div').dom;
197 var pm = this.trigger.child('div/div');
198 pm.removeClass(Roo.bootstrap.form.SecurePass.meterClass);
199 pm.addClass(Roo.bootstrap.form.SecurePass.meterClass[strength]);
201 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
203 pt.innerHTML = Roo.bootstrap.form.SecurePass.meterLabel + ' ' + Roo.bootstrap.form.SecurePass.pwdStrengths[strength];
208 CharacterSetChecks: function (type)
211 this.fResult = false;
214 isctype: function (character, type)
217 case this.kCapitalLetter:
218 if (character >= 'A' && character <= 'Z') {
223 case this.kSmallLetter:
224 if (character >= 'a' && character <= 'z') {
230 if (character >= '0' && character <= '9') {
235 case this.kPunctuation:
236 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
247 IsLongEnough: function (pwd, size)
249 return !(pwd == null || isNaN(size) || pwd.length < size);
252 SpansEnoughCharacterSets: function (word, nb)
254 if (!this.IsLongEnough(word, nb))
259 var characterSetChecks = new Array(
260 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
261 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
264 for (var index = 0; index < word.length; ++index) {
265 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
266 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
267 characterSetChecks[nCharSet].fResult = true;
274 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
275 if (characterSetChecks[nCharSet].fResult) {
280 if (nCharSets < nb) {
286 ClientSideStrongPassword: function (pwd)
288 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
291 ClientSideMediumPassword: function (pwd)
293 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
296 ClientSideWeakPassword: function (pwd)
298 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
303 Roo.bootstrap.form.SecurePass.errors = {
304 PwdEmpty: "Please type a password, and then retype it to confirm.",
305 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
306 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
307 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
308 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
309 FNInPwd: "Your password can't contain your first name. Please type a different password.",
310 LNInPwd: "Your password can't contain your last name. Please type a different password.",
311 TooWeak: "Your password is Too Weak."
314 Roo.bootstrap.form.SecurePass.meterLabel = "Password strength:";
315 Roo.bootstrap.form.SecurePass.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
316 Roo.bootstrap.form.SecurePass.meterClass = [
317 "roo-password-meter-tooweak",
318 "roo-password-meter-weak",
319 "roo-password-meter-medium",
320 "roo-password-meter-strong",
321 "roo-password-meter-grey"