Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,109
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Checking for Upper-Case

    I am reviewing some old code that checks for Password Strength.

    (My goal was to do the checks WITHOUT using Regular Expressions.)

    The code below is supposed to check for at least one Uppercase Letter, but I don't think it works like the person who suggested it thought...

    PHP Code:
        // Check for Uppercase Letter.
        
    if (empty($errors)){
            if (
    strtolower($newPass1) == $newPass1){
                
    $errors['newPass'] = 'Password must have at least 1 Uppercase Letter.';
            }
        } 

    The last row is where it seems to fail...
    Code:
    $newPass1	strtolower($newPass1)	IF()
    ----------	----------------------	------
    debbie		debbie			TRUE
    Debbie		debbie			FALSE
    DEBBIE		debbie			FALSE
    Any suggestions?


    Debbie

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Okay, so what's the problem? With the code you have and that output chart assuming the comparison is done on equality is correct. 'DEBBIE' <> 'debbie', so comparing them for equality would come to false.
    So if the goal is simply to determine if all characters as lower case, than that will do the job.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,109
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Okay, so what's the problem? With the code you have and that output chart assuming the comparison is done on equality is correct. 'DEBBIE' <> 'debbie', so comparing them for equality would come to false.
    So if the goal is simply to determine if all characters as lower case, than that will do the job.
    My brain wasn't working last night.

    BTW, so what would happen if I used this instead... (3 equal signs)

    PHP Code:
            if (strtolower($newPass1) === $newPass1){
                
    $errors['newPass'] = 'Password must have at least 1 Uppercase Letter.';
            } 

    Debbie

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Nothing different; these are already both strings, so the results would be the same. Identical is used for conflicting datatypes like checking 0 === false which is false, while 0 == false is true.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,109
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Nothing different; these are already both strings, so the results would be the same. Identical is used for conflicting datatypes like checking 0 === false which is false, while 0 == false is true.
    Okay, that is what I thought.

    Thanks for the help!


    Debbie


  •  

    Posting Permissions

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