pthurmond Posted December 5, 2006 Share Posted December 5, 2006 How would I go about enforcing password requirements?Here are the ones I want to enforce:Your password must meet the following requirements:-It must be between 6 and 12 characters long.-It must contain at least one lower-case and one upper-case letter.-It must contain at least two numbers.-It must not contain any special characters (Ex. @, #, $, %, &, etc.)Thanks,Patrick Link to comment https://forums.phpfreaks.com/topic/29491-how-would-i-go-about-enforcing-password-requirements/ Share on other sites More sharing options...
Orio Posted December 5, 2006 Share Posted December 5, 2006 Very few regex here...[code]<?phpfunction check_pass($pass){ $len = strlen($pass); if($len < 6 || $len > 12) return "Error - password must be between 6 to 12 charaters long!"; if(ereg("[a-z]", $pass) === FALSE || ereg("[A-Z]", $pass) === FALSE) return "Error - password must contain at least one lower case letter and one upper case letter!"; if(preg_match("/^[a-zA-Z0-9]$/", $pass) == 0) return "Error - the password can only contain alpha-numeric chars!"; if(ereg("[0-9].*[0-9]", $pass) === FALSE) return "Error- password must contain at least two numbers!"; return "The password ".$pass." is good :)"; }?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/29491-how-would-i-go-about-enforcing-password-requirements/#findComment-135626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.