Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/118252-solved-encrypted-password/
Share on other sites

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
}

?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.