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? Link to comment https://forums.phpfreaks.com/topic/43780-password-must-have-x-letters-and-y-numbers-best-method/ 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); Link to comment https://forums.phpfreaks.com/topic/43780-password-must-have-x-letters-and-y-numbers-best-method/#findComment-212557 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 Link to comment https://forums.phpfreaks.com/topic/43780-password-must-have-x-letters-and-y-numbers-best-method/#findComment-213100 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. Link to comment https://forums.phpfreaks.com/topic/43780-password-must-have-x-letters-and-y-numbers-best-method/#findComment-213103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.