User Passwords: checking for unique chars

From: Date: Mon, 14 Feb 2005 15:24:24 +0000
Subject: User Passwords: checking for unique chars
Groups: php.general 
Request: Send a blank email to php-general+get-208637@lists.php.net to get a copy of this message
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

« previous php.general (#208637) next »