Go Back   Cloud Computing > Support > PHP Forum
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-06, 06:45
Junior Member
 
Join Date: Nov 2005
Posts: 14
Default Problem in validation of password

Hi all,


I am having trouble validating passwords which users choose for
themselves. The rules I need to follow are:
Has to be between 7 - 20 chars
Must only contain a-z A-Z 0-9
Must have at least one lowercase, one uppercase and one digit in this.


The validation I am running at the moment is:


if (!ereg("([a-z]{1,}[A-Z]{1,}[0-9]{1,})",$password))
{
$patternmatch='Problem';
}


But this doesn't look right. Could anyone please help?


Many Thanks,
Reply With Quote
  #2 (permalink)  
Old 02-10-06, 01:51
Junior Member
 
Join Date: Nov 2005
Posts: 14
Default

Hi again,

I've found the solution:

if(
ctype_alnum($password) // numbers & digits only
&& strlen($password)>6 // at least 7 chars
&& strlen($password)<21 // at most 20 chars
&& preg_match('`[A-Z]`',$password) // at least one upper case
&& preg_match('`[a-z]`',$password) // at least one lower case
&& preg_match('`[0-9]`',$password) // at least one digit
){
// valid


}else{
// not valid
}

This is a pretty nifty bit of script if you want to ensure that a user chooses a very secure password.

Cheers,
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 01:01.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.