|
Posted by Alex Gemmell on 10/04/64 11:08
Hello!
I'm checking user chosen passwords for validity and have created 7
tests. It's not 100% bulletproof but it will do for now. My problem
is with the last check "have 6 unique characters". I'm at a loss at
how to check for this in a neat one-liner.
My brain is starting to go off on some horribly complicated routines
but I'm sure it can be done neatly (like the regular expressions).
Can anyone help me with this? By the way - I've only just learnt
regular expressions this morning so I'm no expert on them...
########
# Code:
########
function check_password($password) {
# It exists
if ( !isset($password) ) return false;
# Not empty
if ( empty($password) ) return false;
#At least 8 characters long
if ( strlen($password)<8 ) return false;
#Does not contain special characters e.g. (!@#:?<>,./;'`[=\]{space})
if ( !preg_match ('/[][)(.,!@#:?<>\/\\\\;\'`=\\s]/', $password)
) return false;
#Contain at least one number
if ( !preg_match ('/\\d/', $password) ) return false;
#Contain at least one letter
if ( !preg_match ('/[a-zA-Z]/', $password) ) return false;
#Have 6 unique characters
if ( ????????? ) return false;
return true;
}
########
Thanks,
Alex
[Back to original message]
|