Jump to content

MD5 Password Encryption


The14thGOD

Recommended Posts

Hey, I am working on a change password form but I'm having a little problem.

heres the query:
[code]<?php
$query = "UPDATE user SET password=MD5('$password') , signature='$signature' , ";
$query .= "avatar='$file_dir' , status='$status' WHERE username='$username' ";
[/code]

The problem is that when put like that, the password is the encryption. So for example it would be "aa87d6boi71948anva" rather than if then the actual password.

I think that is it because if I log out and come back in the password is not the password i typed. So I did an echo and got the encryption with MD5 and got the password w/o it.

Anyone know how to update and store as a MD5 encryption?

Thanks in advance.
Link to comment
Share on other sites

Thank you. It looks like I have another error /sigh.

Heres the summary:
I'm trying to detect if anything is entered in the password field, and if they match.

1. If they dont match then send back saying so.
2. If password is blank, set password to X.
3. If password exists then newpassword is Y.

heres the code

[code]<?php
$pass_query = "SELECT * FROM user WHERE id=$user_id ";
$pass_result = mysql_query($pass_query);
$pass_row = mysql_fetch_array($pass_result);
if ($password != $confirm_password) {
$error = 'pass';
header("Location: user_prefs.php?error=$error");
exit(0);
}
if ($password == "") {
$newpassword = md5($pass_row[password]);
}
elseif ($password != "") {
$newpassword = md5($password);
}?>[/code]

it is writing to the right row so that shouldn't be a problem..

thanks again.
Link to comment
Share on other sites

What wasn't really said was how you SHOULD be checking passwords.  The most common way I've seen and used is to store the md5'd password hash in the database for the user.  Then when they have to authenticate, you get their username/id and password.  You then retrieve the hash from the DB then md5 the submitted password.  If the retrieved hash and the hashed submission match, then you're authentic.  If not, error/try again/whatever.  That make sense?
Link to comment
Share on other sites

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.