sync
[roojs1] / Roo / bootstrap / SecurePass.js
index 587a88f..bbb84ca 100644 (file)
@@ -29,7 +29,17 @@ Roo.bootstrap.SecurePass = function (config) {
         TooWeak: "Your password is Too Weak."
     },
     this.meterLabel = "Password strength:";
-    this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];    
+    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);
 }
 
@@ -47,10 +57,10 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
      * })
      */
     // private
-    meterClass : ["password-meter-tooweak", "password-meter-weak", "password-meter-medium", "password-meter-strong"],
+    
     meterWidth: 300,
     errorMsg :'',    
-    errors: {},
+    errors: false,
     imageRoot: '/',
     /**
      * @cfg {String/Object} Label for the strength meter (defaults to
@@ -62,8 +72,8 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
      * @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
@@ -76,7 +86,8 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
     
     insecure: false,
     // private
-    initEvents: function () {
+    initEvents: function ()
+    {
         Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
 
         if (this.el.is('input[type=password]') && Roo.isSafari) {
@@ -86,47 +97,38 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
         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': '20px',
-                cls: 'password-meter-container',
-                width: this.meterWidth + 'px'
-            },
-            cn: {
-                tag: 'div',
-                cls: 'password-meter-grey',
-                style: {
-                    width: this.meterWidth + 'px'                                        
-                },
-                cn: [
+                  cn: [
                     {
                     //id: 'PwdMeter',
                     tag: 'div',
-                    cls: 'password-meter-tooweek',
+                    cls: 'roo-password-meter-grey col-xs-12',
                     style: {
                         //width: 0,
-                        width: this.meterWidth + 'px'                                                
+                        //width: this.meterWidth + 'px'                                                
                         }
                     },
                     {                           
-                        cls: 'password-meter-text'                      
+                        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();
@@ -137,7 +139,8 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
         Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
     },
     // private
-    checkStrength: function () {
+    checkStrength: function ()
+    {
         var pwd = this.inputEl().getValue();
         if (pwd == this._lastPwd) {
             return;
@@ -154,43 +157,39 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
             strength = 0;
         }
         
-        console.log('strength1: ' + strength);
+        Roo.log('strength1: ' + strength);
         
         //var pm = this.trigger.child('div/div/div').dom;
-        var pm = this.trigger.child('div/div/div');
+        var pm = this.trigger.child('div/div');
         pm.removeClass(this.meterClass);
         pm.addClass(this.meterClass[strength]);
                 
-        //pm.style.width = (this.meterWidth / 3) * strength + 'px';
-               
         
-        var pt = this.trigger.child('/div/div/').child('>*[class=password-meter-text]').dom;        
+        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;
-        var pm = this.trigger.child('div/div/div');
+        
+        var pm = this.trigger.child('div/div');
         pm.removeClass(this.meterClass);
-        pm.addClass(this.meterClass[0]);        
+        pm.addClass('roo-password-meter-grey');        
         
         
-        var pt = this.trigger.child('/div/div/').child('>*[class=password-meter-text]').dom;        
-                
-        //pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
+        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;
         }
@@ -209,7 +208,7 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
             return true;
         }
         
-        if ('[\x21-\x7e]*'.match(value)) {
+        if (!value.match(/[\x21-\x7e]+/)) {
             this.markInvalid(this.errors.PwdBadChar);
             this.errorMsg = this.errors.PwdBadChar;
             return false;
@@ -235,23 +234,23 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
             strength = 0;
         }
 
-        /*
+        
         if (strength < 2) {
-            this.markInvalid(this.errors.TooWeak);
+            //this.markInvalid(this.errors.TooWeak);
             this.errorMsg = this.errors.TooWeak;
-            return false;
+            //return false;
         }
-        */
+        
         
         console.log('strength2: ' + strength);
         
         //var pm = this.trigger.child('div/div/div').dom;
         
-        var pm = this.trigger.child('div/div/div');
+        var pm = this.trigger.child('div/div');
         pm.removeClass(this.meterClass);
         pm.addClass(this.meterClass[strength]);
                 
-        var pt = this.trigger.child('/div/div/').child('>*[class=password-meter-text]').dom;        
+        var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;        
                 
         pt.innerHTML = this.meterLabel + '&nbsp;' + this.pwdStrengths[strength];
         
@@ -259,52 +258,62 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
         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)) {
@@ -327,15 +336,18 @@ Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
         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);
     }