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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.