From: Alex Gemmell [mailto:[EMAIL PROTECTED] 

> 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...

The quick & dirty way, I think, would be the following:

<?

// create an assoc. array of the chars
$pass_chars = array();
for ($i = 0; $i < strlen($password); $i++) {
        $pass_chars[substr($password, $i, 1)]++;
}
// array keys are the # of unique chars
if (count($pass_chars) < 6) return FALSE;

?>

I'm curious to see if there's an easier way to do it, though. I'm not
sure regexps are the answer.


-- 
Mike Johnson             Smarter Living, Inc.
Web Developer            www.smartertravel.com
[EMAIL PROTECTED]   (617) 886-5539

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to