Jump to content

How would I go about enforcing password requirements?


pthurmond

Recommended Posts

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
Very few regex here...

[code]<?php

function 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.