littlepeg Posted June 1, 2007 Share Posted June 1, 2007 Hi everybody, would you please help me with this password validation problems. I want to check whether the password length is more than 6 characters, if not, shows error message. But I think there is something wrong with my codes, because it did not check whether the password is over 6 characters. Any help will be appreciated and grateful. Thank you. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { if (strlen($_POST['password1']<6) { $errors[]='Your password must be at least 6 characters long.';} else{ $p = $_POST['password1'];} } } else { $errors[] = 'You forgot to enter your password.'; } Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/ Share on other sites More sharing options...
MemphiS Posted June 1, 2007 Share Posted June 1, 2007 if (strlen($_POST['password1'])<6){ Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266171 Share on other sites More sharing options...
littlepeg Posted June 1, 2007 Author Share Posted June 1, 2007 Oh, yes. Thank you. You found a mistake for me. I changed it. However, it is still not working, still could not check 6 characters for the entered password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { [color=red]if (strlen($_POST['password1'])<6) [/color]{ $errors[]='Your password must be at least 6 characters long.';} else{ $p = $_POST['password1'];} } } else { $errors[] = 'You forgot to enter your password.'; } Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266180 Share on other sites More sharing options...
MemphiS Posted June 1, 2007 Share Posted June 1, 2007 This is how i would do it... <?php if (!empty(addslashes($_POST['password1']))){ /* Security .. check for valid data ctype_alnum checks for letters,numbers */ if (!ctype_alnum($_POST['password1'])){ $errors[] = 'Your password was invalid.'; }elseif (ctype_alnum($_POST['password1'])){ if ($_POST['password1'] != $_POST['password2']){ $errors[] = 'Your password did not match the confirmed password.'; }elseif ($_POST['password1'] == $_POST['password2']){ if (strlen($_POST['password1'])<6){ $errors[]='Your password must be at least 6 characters long.'; }elseif (strlen($_POST['password1'])>=6){ $p = $_POST['password1']; }else{ $errors[] = 'You forgot to enter your password.'; }}}} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266183 Share on other sites More sharing options...
littlepeg Posted June 1, 2007 Author Share Posted June 1, 2007 Thank you very much. I have a try now Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266194 Share on other sites More sharing options...
littlepeg Posted June 1, 2007 Author Share Posted June 1, 2007 Hi, thank you. I tried it, but somehow still not working. :'( Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266202 Share on other sites More sharing options...
MemphiS Posted June 1, 2007 Share Posted June 1, 2007 What is the error your getting... Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266213 Share on other sites More sharing options...
littlepeg Posted June 1, 2007 Author Share Posted June 1, 2007 There is no error. It just when I put three characters in for password, the value will be accepted rather than prompt a error message says: "Your password must be at least 6 characters long". :'( Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266217 Share on other sites More sharing options...
MemphiS Posted June 1, 2007 Share Posted June 1, 2007 <?php if (isset($_POST['password1'])){ if (!ctype_alnum($_POST['password1'])){ echo "Your password was invalid."; }elseif (ctype_alnum($_POST['password1'])){ if ($_POST['password1'] != $_POST['password2']){ echo "Your password did not match the confirmed password."; }elseif ($_POST['password1'] == $_POST['password2']){ if (strlen($_POST['password1'])<6){ echo "Your password must be at least 6 characters long."; }elseif (strlen($_POST['password1'])>=6){ $p = $_POST['password1']; }else{ echo "You forgot to enter your password."; }}}} ?> This should work.. Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266230 Share on other sites More sharing options...
littlepeg Posted June 1, 2007 Author Share Posted June 1, 2007 Hi, it works well now. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266239 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.