icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old March 1st, 2006, 8:02 AM   #1 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
Stupid Person Error Checking

Atleast, that's what I began calling it when it popped in my head the other day:

Quote:
if ($_POST['cl_pass'] = preg_match("/password/i",$_POST['cl_pass'])){
$error = "ARG!<br/>You can NOT make your password \"Password\"!";
}
Thought I would share. Thoughts? Anything to add to make it more efficient. All it does is check to make sure they aren't doing any variation of Password as their password.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 11:37 AM   #2 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
Code:
<?php
if (strpos(strtolower($_POST['cl_pass']),'password')) {
$error = "ARG!<br/>You can NOT make your password \"Password\"!";
}
?>
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 6:50 PM   #3 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
Ok. Now, why is that more efficient? An explination would help, as per usual with me. It just seems like running two functions verses one would not be better.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:04 PM   #4 (permalink)
All Ur Base R Belong 2 Us
Excelling Contributor
 
mr_fern's Avatar
 
Joined in Feb 2005
Lives in Vegas & New York
824 posts
Gave thanks: 2
Thanked 6 times
Regular expressions are more "expensive" on the CPU than regular string matching.

That's why they suggest using string matching instead of pattern matching for simple searches (i.e. a particular word is in a word/sentence)
__________________
Nobody doing nothing
mr_fern is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:09 PM   #5 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
Ok, and using the above method would work as a case-insensitive search? That's why I went with regex in the first place, was because I couldn't find another way to find case variations of the word.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:15 PM   #6 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
Ok, I think I understand now. strtolower will lowercase it all if the word is Password. But will it do it if it's PasSWorD? Of course, I guess I could just try it and find out.

edit: ok, I tried it and it didn't work at all any more. Every variation of the word password that I tried was submitted successfully.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.

Last edited by David; March 1st, 2006 at 8:21 PM..
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:43 PM   #7 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
Ok, I know what it's not working. If you start password as the first character, it sets the value to 0, or false.

PHP Code:
<?php
if (strpos('_'.strtolower($_POST['cl_pass']),'password')) {
$error "ARG!<br/>You can NOT make your password \"Password\"!";
}
?>
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:45 PM   #8 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
I'm not following. I see that you added the '_' to it, but I'm not understanding what that just did.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old March 1st, 2006, 8:46 PM   #9 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
Ack.. What was I thinking?

PHP Code:
<?php
if (strstr(strtolower($_POST['cl_pass']),'password')) {
$error "ARG!<br/>You can NOT make your password \"Password\"!";
}
?>
Using strstr() doesn't check for the position, while strpos() does. Doh!
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On