Jump to content

md5 question


webguync

Recommended Posts

I have code which scrambles password info using MD5. The scipt authenticates the username and password against the database info and proceeds to a secure page if the info is correct.

$password = mysql_real_escape_string(md5($_POST['pwid']));

 

my question is how do I know which scrambled code to put into the database?

Link to comment
Share on other sites

alternative method of determining what the MD5 hash is

This is an odd question.  What exactly do you mean by alternative method?  If you want to calculate an md5 hash in PHP code then you use the built-in function named md5() and you pass it one argument, the value you want hashed.

 

Therefore if you want to use md5 to hash the value google using a PHP program, your program would contain at least this:

<?php
md5( 'google' );
?>

 

Now that small program calculates the md5 hash of the value google, but it doesn't echo the value nor does it save it in a variable, file, or database.

 

So you probably want at least this much:

<?php
$hashed = md5( 'google' );
?>

 

That calculates the md5 and stores it in the variable $hashed.  But the value in $hashed is not used for anything.

 

So here is where you decide what to do with the hashed value.

 

Will you echo it to the screen?

<?php
$hashed = md5( 'google' );
echo $hashed;
?>

 

Will you insert it into a database?

<?php
$hashed = md5( 'google' );
$user = 'joesmith';
$db = mysql_connect( 'host', 'user', 'pass', 'dbname' );
// Not that I've not called mysql_real_escape_string, but you should!
mysql_query( "insert into users ( username, password ) values ( '{$user}', '{$hashed}' )" );
?>

 

Most of us are having a hard time figuring out exactly what you're asking.

Link to comment
Share on other sites

I think the confusion is with the script I have, the username and passwords are stored in the DB ahead of time not entered into the DB via a form. I manually enter the info into the database, so in the past I would enter username:myemail@aol.com password:google. But with the MD5 hash, I don't know what that is unless I echo out the Query or use another hash script.

Link to comment
Share on other sites

MySQL has MD5() function as well, so issue a query like this from PhpMyAdmin for example:

INSERT INTO yourTable(usernameColumn, passwordColumn) VALUES ('yourYsername',MD5('yourPassword'));

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.