Jump to content

Password Must have X letters and Y numbers, Best method?


corbin

Recommended Posts

Whew been a while since I've posted on here... Dunno if that's good or bad >.<.

 

Anyway, I'm coding a script and the password needs to be very very secure.  I figured I would make the password have to contain a minimum of 2 numbers, but realized I don't know the best method to do that.  At first I thought regexp, but I couldn't figure out how to do it with a regexp since I would have to allow alpha chars all over the place and what not.

 

So far I'm using something like:

$str2 = (int) $str;

if(strlen($str2) < 2) {

//fail

}

 

Is there a better way to do this?

You can use this, along with a second pass to count up the categories.

 

http://sg2.php.net/manual/en/function.count-chars.php

 

Or a suitable regexp could be

 

$digits = preg_replace('|[^0-9]|', '', $str);
$digits_count = strlen($digits);
$alphas = preg_replace('|[^a-zA-Z]|', '', $str);
$alphas_count = strlen($alphas);

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.