I am trying to make my password not contain the all OR part of the username. I'm not real sure how to do this... If the username is "User123" I would not like the password to contain the following (in any caps/not caps scheme): use ser er1 r12 123 The only thing I can think of is to use a strtoupper/lower and then do a foreach loop using substr and going one space at a time. I'm hoping there's something easier than that though. Thanks in advance!
Use this, if the password is inside the username you can show an error. if (stripos($username, $password) !== false) { //error } PHP:
Indeed it is, you should really update.. In the mean time: if (strpos(strtolower($username), strtolower($password)) !== false) { } PHP:
If you want "User123" not to match even "xxserxx" you should use something like this function compareStrings ($firstString, $secondString, $maxInCommon) { for ($i = 0; $i <= strlen($firstString) - $maxInCommon; $i ++) { if (strpos(strtolower($secondString), strtolower(substr($firstString, $i, $maxInCommon))) !== false) { return false; } } return true; } PHP: so you can call it like this: $username = "User123"; $password = "xxusexx"; echo compareStrings($username, $password, 3) ? "Password valid" : "Password invalid, too similar to username"; PHP: EDIT: I see you got your problem solved, but I'll let this small function stay here, someone could make an use of it =)
Excellent function gray fox Though to the original poster, I don't think you should be so restrictive in your passwords. It will only aggrevate users signing up. Ofcourse it depends on which app you're building.
strpos is also available for PHP4, the difference however is that in PHP4 , strpos will only search for a single character instance instead of an entire string.