corbin Posted March 22, 2007 Share Posted March 22, 2007 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? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 22, 2007 Share Posted March 22, 2007 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); Quote Link to comment Share on other sites More sharing options...
corbin Posted March 22, 2007 Author Share Posted March 22, 2007 Ooooohhh thanks.... Didn't think about replacing things that weren't the type... lol Quote Link to comment Share on other sites More sharing options...
Scriptor Posted March 22, 2007 Share Posted March 22, 2007 You could also use is_numeric function in a loop to test if a character is a number or not. 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.