},
this.meterLabel = "Password strength:";
this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
+ this.meterClass = [
+ "roo-password-meter-tooweak",
+ "roo-password-meter-weak",
+ "roo-password-meter-medium",
+ "roo-password-meter-strong",
+ "roo-password-meter-grey"
+ ];
+
+ this.errors = {};
+
Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
}
* })
*/
// private
+
meterWidth: 300,
- errors: {},
+ errorMsg :'',
+ errors: false,
imageRoot: '/',
/**
* @cfg {String/Object} Label for the strength meter (defaults to
* @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
* ['Weak', 'Medium', 'Strong'])
*/
- // private
- pwdStrengths: [],
+ // private
+ pwdStrengths: false,
// private
strength: 0,
// private
insecure: false,
// private
- initEvents: function () {
+ initEvents: function ()
+ {
Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
if (this.el.is('input[type=password]') && Roo.isSafari) {
this.el.on('keyup', this.checkStrength, this, {buffer: 50});
},
// private
- onRender: function (ct, position) {
+ onRender: function (ct, position)
+ {
Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
this.trigger.createChild({
- tag: 'div',
- style: {
- 'margin-bottom': '10px',
- width: this.meterWidth + 'px'
- },
- cn: {
- tag: 'div',
- cls: 'password-meter-grey',
- style: {
- width: this.meterWidth + 'px',
- height: '10px'
- },
- cn: [{
+ cn: [
+ {
//id: 'PwdMeter',
tag: 'div',
- cls: 'password-meter',
+ cls: 'roo-password-meter-grey col-xs-12',
style: {
//width: 0,
- height: '10px'
+ //width: this.meterWidth + 'px'
+ }
},
- {
- tag: 'div',
- cls: 'password-meter1',
- style: {
- //width: 0,
- height: '10px'
+ {
+ cls: 'roo-password-meter-text'
}
- }]
- }
+ ]
});
+
+
if (this.hideTrigger) {
this.trigger.setDisplayed(false);
}
this.setSize(this.width || '', this.height || '');
},
// private
- onDestroy: function () {
+ onDestroy: function ()
+ {
if (this.trigger) {
this.trigger.removeAllListeners();
this.trigger.remove();
Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
},
// private
- checkStrength: function () {
+ checkStrength: function ()
+ {
var pwd = this.inputEl().getValue();
if (pwd == this._lastPwd) {
return;
} else {
strength = 0;
}
- var pm = this.trigger.child('div/div/div').dom;
- console.log('strength1: ' + strength);
- pm.style.width = (this.meterWidth / 3) * strength + 'px';
- //if(this.pwdStrengths != null && strength > 0) {
- pm.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
- //} else {
- // pm.innerHTML = '';
- //}
+ Roo.log('strength1: ' + strength);
+
+ //var pm = this.trigger.child('div/div/div').dom;
+ var pm = this.trigger.child('div/div');
+ pm.removeClass(this.meterClass);
+ pm.addClass(this.meterClass[strength]);
+
+
+ var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
+
+ pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
this._lastPwd = pwd;
},
- reset: function () {
+ reset: function ()
+ {
Roo.bootstrap.SecurePass.superclass.reset.call(this);
+
this._lastPwd = '';
- var pm = this.trigger.child('div/div/div').dom;
- pm.style.width = 0;
- pm.innerHTML = '';
+
+ var pm = this.trigger.child('div/div');
+ pm.removeClass(this.meterClass);
+ pm.addClass('roo-password-meter-grey');
+
+
+ var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
+
+ pt.innerHTML = '';
+ this.inputEl().dom.type='password';
},
// private
- validateValue: function (value) {
+ validateValue: function (value)
+ {
if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
return false;
}
this.markInvalid(this.errors.PwdEmpty);
+ this.errorMsg = this.errors.PwdEmpty;
return false;
}
if ('[\x21-\x7e]*'.match(value)) {
this.markInvalid(this.errors.PwdBadChar);
+ this.errorMsg = this.errors.PwdBadChar;
return false;
}
if (value.length < 6) {
this.markInvalid(this.errors.PwdShort);
+ this.errorMsg = this.errors.PwdShort;
return false;
}
if (value.length > 16) {
this.markInvalid(this.errors.PwdLong);
+ this.errorMsg = this.errors.PwdLong;
return false;
}
var strength;
} else {
strength = 0;
}
+
if (strength < 2) {
- this.markInvalid(this.errors.TooWeak);
- return false;
+ //this.markInvalid(this.errors.TooWeak);
+ this.errorMsg = this.errors.TooWeak;
+ //return false;
}
+
+
console.log('strength2: ' + strength);
- var pm = this.trigger.child('div/div/div').dom;
-
- pm.style.width = (this.meterWidth / 3) * strength + 'px';
-
- pm.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
+
+ //var pm = this.trigger.child('div/div/div').dom;
+
+ var pm = this.trigger.child('div/div');
+ pm.removeClass(this.meterClass);
+ pm.addClass(this.meterClass[strength]);
+ var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
+
+ pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
+
+ this.errorMsg = '';
return true;
},
// private
- CharacterSetChecks: function (type) {
+ CharacterSetChecks: function (type)
+ {
this.type = type;
this.fResult = false;
},
// private
- isctype: function (character, type) {
- switch (type) { //why needed break after return in js ? very odd bug
+ isctype: function (character, type)
+ {
+ switch (type) {
case this.kCapitalLetter:
if (character >= 'A' && character <= 'Z') {
return true;
}
break;
+
case this.kSmallLetter:
if (character >= 'a' && character <= 'z') {
return true;
}
break;
+
case this.kDigit:
if (character >= '0' && character <= '9') {
return true;
}
break;
+
case this.kPunctuation:
if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
return true;
}
break;
+
default:
return false;
}
},
// private
- IsLongEnough: function (pwd, size) {
+ IsLongEnough: function (pwd, size)
+ {
return !(pwd == null || isNaN(size) || pwd.length < size);
},
// private
- SpansEnoughCharacterSets: function (word, nb) {
+ SpansEnoughCharacterSets: function (word, nb)
+ {
if (!this.IsLongEnough(word, nb))
{
return false;
}
var characterSetChecks = new Array(
- new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
- new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation));
+ new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
+ new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
+ );
+
for (var index = 0; index < word.length; ++index) {
for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
return true;
},
// private
- ClientSideStrongPassword: function (pwd) {
+ ClientSideStrongPassword: function (pwd)
+ {
return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
},
// private
- ClientSideMediumPassword: function (pwd) {
+ ClientSideMediumPassword: function (pwd)
+ {
return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
},
// private
- ClientSideWeakPassword: function (pwd) {
+ ClientSideWeakPassword: function (pwd)
+ {
return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
}