2 //<script type="text/Javascript">
5 Ext.form.SecurePass = function(config) {
6 // these go here, so the translation tool can replace them..
8 PwdEmpty: "Please type a password, and then retype it to confirm.",
9 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
10 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
11 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
12 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
13 FNInPwd: "Your password can't contain your first name. Please type a different password.",
14 LNInPwd: "Your password can't contain your last name. Please type a different password.",
15 TooWeak: "Your password is Too Weak."
17 this.meterLabel = "Password strength:";
18 this.pwdStrengths = ["Too Weak" , "Weak", "Medium", "Strong"];
19 Ext.form.SecurePass.superclass.constructor.call(this, config);
22 Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
24 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
26 * PwdEmpty: "Please type a password, and then retype it to confirm.",
27 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
28 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
29 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
30 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
31 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
32 * LNInPwd: "Your password can't contain your last name. Please type a different password."
41 * @cfg {String/Object} Label for the strength meter (defaults to
42 * 'Password strength:')
48 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
49 * ['Weak', 'Medium', 'Strong'])
55 * @cfg {String/Object} fieldsFilter A fieldsFilter spec, as [['field_name', 'error_id'], ...]
73 initEvents : function(){
75 Ext.form.SecurePass.superclass.initEvents.call(this);
76 this.el.on('keyup', this.checkStrength, this, {buffer:50});
80 onRender : function(ct, position){
81 Ext.form.SecurePass.superclass.onRender.call(this, ct, position);
82 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
83 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter '+this.triggerClass});
85 this.trigger.createChild({
88 'margin-bottom': '10px',
89 width: this.width + 'px'
94 width: this.width + 'px',
96 'background-image' : 'url(\''+this.imageRoot+'/password_meter_grey.gif\')',
97 'background-position' : 'center center',
98 'background-repeat': 'no-repeat'
106 'background-image': 'url(\''+this.imageRoot+'/password_meter.gif\')',
107 'background-position': 'center center',
108 'background-repeat': 'no-repeat',
114 if(this.hideTrigger){
115 this.trigger.setDisplayed(false);
117 this.setSize(this.width||'', this.height||'');
121 onDestroy : function(){
123 this.trigger.removeAllListeners();
124 this.trigger.remove();
129 Ext.form.TriggerField.superclass.onDestroy.call(this);
133 checkStrength : function(){
134 var pwd = this.el.getValue();
135 if (pwd == this._lastPwd) {
140 if (this.ClientSideStrongPassword(pwd)) {
142 } else if(this.ClientSideMediumPassword(pwd)) {
144 } else if(this.ClientSideWeakPassword(pwd)) {
149 var pm = this.trigger.child('div/div/div').dom;
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 Ext.form.SecurePass.superclass.reset.call(this);
163 var pm = this.trigger.child('div/div/div').dom;
168 validateValue : function(value){
169 if (!Ext.form.TextField.superclass.validateValue.call(this, value)){
172 if (value.length == 0) {
173 if (this.allowBlank) {
178 this.markInvalid(this.errors.PwdEmpty);
181 if ('[\x21-\x7e]*'.match(value)) {
182 this.markInvalid(this.errors.PwdBadChar);
185 if (value.length < 6) {
186 this.markInvalid(this.errors.PwdShort);
189 if (value.length > 16) {
190 this.markInvalid(this.errors.PwdLong);
194 if (this.ClientSideStrongPassword(value)) {
196 } else if(this.ClientSideMediumPassword(value)) {
198 } else if(this.ClientSideWeakPassword(value)) {
204 this.markInvalid(this.errors.TooWeak);
208 for (var index = 0; index < this.fieldsFilter.length; ++index) {
209 filter = document.getElementById(this.fieldsFilter[index][0]).value;
212 re = new RegExp(filter);
213 if (re.test(value)) {
214 this.markInvalid(eval('this.errors.'+ this.fieldsFilter[index][1]));
224 CharacterSetChecks : function(type){
226 this.fResult = false;
230 isctype : function(character, type){
231 switch (type) { //why needed break after return in js ? very odd bug
232 case this.kCapitalLetter: if (character >= 'A' && character <= 'Z') { return true; } break;
233 case this.kSmallLetter: if (character >= 'a' && character <= 'z') { return true; } break;
234 case this.kDigit: if (character >= '0' && character <= '9') { return true; } break;
235 case this.kPunctuation: if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) { return true; } break;
236 default: return false;
242 IsLongEnough : function(pwd, size){
243 return !(pwd == null || isNaN(size) || pwd.length < size);
247 SpansEnoughCharacterSets : function(word, nb){
248 if (!this.IsLongEnough(word, nb))
253 var characterSetChecks = new Array(
254 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
255 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation));
256 for (var index = 0; index < word.length; ++index) {
257 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
258 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
259 characterSetChecks[nCharSet].fResult = true;
266 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
267 if (characterSetChecks[nCharSet].fResult) {
272 if (nCharSets < nb) {
279 ClientSideStrongPassword : function(pwd){
280 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
284 ClientSideMediumPassword : function(pwd){
285 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
289 ClientSideWeakPassword : function(pwd){
290 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);