You are here: User Passwords: checking for unique chars « PHP « IT news, forums, messages
User Passwords: checking for unique chars

Posted by Alex Gemmell on 10/02/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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация