RE: User Passwords: checking for unique chars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alex Gemmell [mailto:agemmell@xxxxxxxxx] 

> 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
mike@xxxxxxxxxxxxxxxxx   (617) 886-5539

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux