I need help creating some code to check and make sure that the password does not contain the username within it. For instance: Username: blah Password: blah123 or Username: blah Password: 12blah34 I need to make sure that the username is no where in the password. Thanks
Just use the strpos() function... $password = 'abcdefghijk'; $username = 'cdef'; if(strpos($password , $username )) { echo "The username can not be contained in the password." //print the form again. } ?> PHP:
There is a small problem with kjewat's code, strpos will return 0 if the username is at the start of the password. This means the example code will allow exactly the same username and password. I'd suggest replacing the strpos line with if(stripos($password, $username)!==false) Code (markup): which checks against boolean false (which is returned only if the string is not found) and not 0 or ''. It's also case insensitive so using an uppercase version of the username in the password isn't allowed. The php man page for stripos probably explains it better than I just have.
yelp...I figured that part out...he just helped to give me the direction to go in But thanks for clarifying that...
you also can lowercase both of variables to check, if password not containt username without depending on char case