SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    password strength works fine on firefox but not IE, help please

    Here is my code, it works perfect on Firefox but not at all on IE. If you can help it would be appreciated.

    Code:
    var giTest = 0;
    
    function passStrength() 
    {
       var iTest = 0;
       var strInput = $F('password');
    
           if (strInput.length > 5) {iTest++;}
           if (strInput.match(/[A-Z]/)) {iTest++;}
           if (strInput.match(/[0-9]/)) {iTest++;}
    
           for (var i = 0; i <= strInput.length;i++) {
               if (strInput.charCodeAt(i) >= 33 && strInput.charCodeAt(i) <= 47) {iTest++; break;}
           }
    
           if (strInput.length <= 5) {iTest = 0;}
    
           switch (iTest) {
              case 0: if (iTest  < giTest){document.getElementById('pStrength').style.backgroundColor = '#ff9999';} 
              case 1: if (giTest < iTest) { 
    					document.getElementById('pStrength').style.backgroundColor = '#ffbf99';  
    				} else if (iTest < giTest) {
    					document.getElementById('pStrength').style.backgroundColor = '#ff9999';
    				} break;
              case 2: if (giTest < iTest) { 
    					document.getElementById('pStrength').style.backgroundColor = '#fff499';  
    				} else if (iTest < giTest) {
    					document.getElementById('pStrength').style.backgroundColor = '#ffbf99';
    				} break;
    
              case 3: if (giTest < iTest) { 
    					document.getElementById('pStrength').style.backgroundColor = '#f2ff99';  
    				} else if (iTest < giTest) {
    					document.getElementById('pStrength').style.backgroundColor = '#fff499';
    				} break;
              case 4: if (giTest < iTest) { 
    					document.getElementById('pStrength').style.backgroundColor = '#a5ff99';  
    				} else if (iTest < giTest) {
    					document.getElementById('pStrength').style.backgroundColor = '#f2ff99';
    				} break;
           }
           giTest = iTest;
    }

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, I thought this would be an easy answer for most of you guys. But seems to have even the pros stumped.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    last try, anyone??

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You provided neither the example code (what is 'pStrength'? how do you call your function?) nor did you describe your problem ("it doesn't work" is not a description). No wonder that noone replied.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem.

    This is a script to test the strength of a password, after each key up event in a password input it runs this function to test the strength and then depending on the results of the test it changes the background-color of a div to reflect. Red is bad green is good type of a thing.

    pStrength is a password input.

    The function is called by onkeyup="passStrength();"

    And as far as the problem, well I don't knwo how else to describe it. Like I said it works fine in Fire Fox however in IE nothing happens.

    Sorry stereofrog I just presumed that the above were all common sense from looking at the code. One day I will learn to stop presuming, always gets me into trouble

    If you or anyone else could it would be greatly appreciated. Thanks

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Try this: (reformatted for me)

    Code:
    var giTest = 0;
    
    function passStrength() {
    
        var iTest = 0;
    
        //var strInput = $F('password');
        var strInput = document.getElementById('pStrength');
    
        if (strInput.value.length > 5) {
            iTest++;
        }
        
        if (strInput.value.match(/[A-Z]/)) {
            iTest++;
        }
        
        if (strInput.value.match(/[0-9]/)) {
            iTest++;
        }
        
        for (var i = 0; i <= strInput.value.length;i++) {
            if (strInput.value.charCodeAt(i) >= 33 && strInput.value.charCodeAt(i) <= 47) {
                iTest++;
                break;
            }
        }
        
        if (strInput.value.length <= 5) {
            iTest = 0;
        }
        
        switch (iTest) {
            case 0:
                if (iTest  < giTest) {
                    strInput.style.backgroundColor = '#ff9999';
                }
            break;
            
            case 1:
                if (giTest < iTest) {
                    strInput.style.backgroundColor = '#ffbf99';
                } else if (iTest < giTest) {
                    strInput.style.backgroundColor = '#ff9999';
                }
            break;
            
            case 2:
                if (giTest < iTest) {
                    strInput.style.backgroundColor = '#fff499';
                } else if (iTest < giTest) {
                    strInput.style.backgroundColor = '#ffbf99';
                }
            break;
            
            case 3:
                if (giTest < iTest) {
                    strInput.style.backgroundColor = '#f2ff99';
                } else if (iTest < giTest) {
                    strInput.style.backgroundColor = '#fff499';
                }
            break;
            
            case 4:
                if (giTest < iTest) {
                    strInput.style.backgroundColor = '#a5ff99';
                } else if (iTest < giTest) {
                    strInput.style.backgroundColor = '#f2ff99';
                }
            break;
        }
        
        giTest = iTest;
    }
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •