widgets/SecurePass.js
[Pman.Core] / widgets / SecurePass.js
index 46a3059..ddbf061 100644 (file)
@@ -71,8 +71,16 @@ Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
 
     // private
     initEvents : function(){
-        Ext.form.SecurePass.superclass.initEvents.call(this);
-               this.el.on('keyup', this.checkStrength, this, {buffer:50});
+            Ext.form.SecurePass.superclass.initEvents.call(this);
+        
+            if(this.el.is('input[type=password]') && Roo.isSafari){
+                this.el.on('keydown', this.SafariOnKeyDown, this);
+//                this.el.on("focus", function(){
+//                    this.setValue('');
+//                }, this);
+            }
+
+            this.el.on('keyup', this.checkStrength, this, {buffer:50});
        },
 
        // private
@@ -165,7 +173,58 @@ Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
     },
     // private
        validateValue : function(value){
-            Roo.log(value);
+               if (!Ext.form.TextField.superclass.validateValue.call(this, value)){
+            return false;
+        }
+               if (value.length == 0) {
+            if (this.allowBlank) {
+                this.clearInvalid();
+                return true;
+            }
+            
+                       this.markInvalid(this.errors.PwdEmpty);
+            return false;
+               }
+               if ('[\x21-\x7e]*'.match(value)) {
+                       this.markInvalid(this.errors.PwdBadChar);
+            return false;
+               }
+               if (value.length < 6) {
+                       this.markInvalid(this.errors.PwdShort);
+            return false;
+               }
+               if (value.length > 16) {
+                       this.markInvalid(this.errors.PwdLong);
+            return false;
+               }
+        var strength;
+               if (this.ClientSideStrongPassword(value)) {
+                       strength = 3;
+               } else if(this.ClientSideMediumPassword(value)) {
+                       strength = 2;
+               } else if(this.ClientSideWeakPassword(value)) {
+                       strength = 1;
+               } else {
+                       strength = 0;
+               }
+        if (strength < 2) {
+                       this.markInvalid(this.errors.TooWeak);
+            return false;
+               }
+        /*
+               for (var index = 0; index < this.fieldsFilter.length; ++index) {
+                       filter = document.getElementById(this.fieldsFilter[index][0]).value;
+                       if (filter != '')
+                       {
+                               re = new RegExp(filter);
+                               if (re.test(value)) {
+                                       this.markInvalid(eval('this.errors.'+ this.fieldsFilter[index][1]));
+                                       return false;
+                               }
+                       }
+               }
+        */
+               return true;
        },
 
     // private
@@ -236,5 +295,15 @@ Ext.extend(Ext.form.SecurePass, Ext.form.TextField, {
     // private
        ClientSideWeakPassword : function(pwd){
                return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
-       }
+       },
+        
+    // private
+        SafariOnKeyDown : function(event){
+            Roo.log(this.el);
+            Roo.log(this.el.selectionStart);
+            if((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1){ // backspace and delete key
+                event.preventDefault();
+                this.setValue('');
+            };
+        }
 })
\ No newline at end of file