ngreenwood6 Posted August 5, 2008 Share Posted August 5, 2008 I have a script where users can login and register for my site. I have just created a page where users can reset their password. I am trying to do the error handling section of it right now. I am trying to make it so that if they do not enter a password into the form it tells them they must enter a password. I have this code: if (empty($new_pass) { echo ("You must enter a password"); } The problem is that it submits it no matter what. I just figured out why, but I don't know how to fix it. The reason is because the password is encrypted. So if they don't enter a password it still gives them a value of something crazy like "dakjk389934532" (md5 hash). Does anyone know how to fix it so that it will check to make sure that they have entered a value? Quote Link to comment https://forums.phpfreaks.com/topic/118252-solved-encrypted-password/ Share on other sites More sharing options...
JonnoTheDev Posted August 5, 2008 Share Posted August 5, 2008 Only encrypt if the password is entered: if(strlen(trim($_POST['password']))) { $newPass = md5($_POST['password']); // update database } else { echo "Please enter a password"; } Quote Link to comment https://forums.phpfreaks.com/topic/118252-solved-encrypted-password/#findComment-608556 Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2008 Author Share Posted August 5, 2008 Thanks for the reply. I got it working with your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/118252-solved-encrypted-password/#findComment-608562 Share on other sites More sharing options...
mbeals Posted August 5, 2008 Share Posted August 5, 2008 where are you applying the hash? perform your validation on the submitted password before hashing: <?php $pass = $_POST['pass']; if($pass) $hash = md5($pass); ?> Now...I wouldn't do it exactly like that. I'd write a function that does more validation first: <?php function validate($pass){ if(!$pass) return 0; if(!preg_match("some regex", $pass) return 0; ## more conditions return md5($pass); } if($hash = validate($_POST['pass'])){ #do something with the valid hashed password } ?> Quote Link to comment https://forums.phpfreaks.com/topic/118252-solved-encrypted-password/#findComment-608564 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.