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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.