Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2013, 04:22 AM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
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
doubledee is offline   Reply With Quote
Old 01-21-2013, 04:48 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-21-2013, 04:39 PM   PM User | #3
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
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
doubledee is offline   Reply With Quote
Old 01-21-2013, 04:56 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-21-2013, 05:11 PM   PM User | #5
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
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
doubledee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:01 AM.


Advertisement
Log in to turn off these ads.