karldesign Posted April 1, 2008 Share Posted April 1, 2008 Hi all, I am doing a registration for a website and want to check the password meets the following requirements: 1) 6 chars at least 2) A-Z/a-z/0-9 only (no characters) I have worked out how to check for (1) - if(strlen($_POST['formPassword']) < 6) - and I just need to work out how to check for just letters and numbers (2). Any help would be great... Link to comment https://forums.phpfreaks.com/topic/98969-password-integrity/ Share on other sites More sharing options...
karldesign Posted April 1, 2008 Author Share Posted April 1, 2008 Does anyone know if this will be enough..? if(!eregi("[a-z0-9]", $_POST['formPassword'])){ //invalid - not text or numbers } else if(eregi(" ", $_POST['formPassword'])){ //invalid - has space } Link to comment https://forums.phpfreaks.com/topic/98969-password-integrity/#findComment-506419 Share on other sites More sharing options...
Orio Posted April 1, 2008 Share Posted April 1, 2008 The best way to check if a string is alphanumeric (Has only letters/numbers) imo is using ctype_alnum(). Example: <?php $str = '12abCD19z4'; if (ctype_alnum($str)) { echo "Letters or digits only"; ?> In the tests I've made in the past, this function was faster than using preg_match() ot eregi(). If you still wanna go for the eregi() way: <?php if(eregi("^[0-9a-z]{6,}$", $_POST['formPassword'])) echo "Letters or digits only, and six chars at least"; ?> This would also check if the string has at least 6 chars Orio. Link to comment https://forums.phpfreaks.com/topic/98969-password-integrity/#findComment-506429 Share on other sites More sharing options...
karldesign Posted April 1, 2008 Author Share Posted April 1, 2008 this allows such characters as '@' though... I don't want users to be able to select anythin but letters or numbers... the ctype_alnum() function works fine though. thanks Link to comment https://forums.phpfreaks.com/topic/98969-password-integrity/#findComment-506432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.