Log in

View Full Version : MySQL Encryption



MrStretch
02-09-2006, 10:58 AM
Hey.

Im sort of new to MySQL. Im combining it with PHP to create a user system. I am using phpmyadmin to manage my databases.

I was wondering, how do i encrypt my password field? I know how to encrypt passwords AFTER they have been added, but how do i get it too encrypt my password field automaticly when its added?

Thanks, MrStretch

Luckyrare
02-09-2006, 11:13 AM
You just use md5() before saving it onto the database

MrStretch
02-09-2006, 11:28 AM
Ok.

This is the query to insert the information from the form into the database. Can you add the md5() function into it? Im not sure where to put it.

mysql_query("INSERT INTO members SET name='{$HTTP_POST_VARS['username']}', creds='{$HTTP_POST_VARS['creds']}', password='{$HTTP_POST_VARS['password']}'")

Thanks :-)

Luckyrare
02-09-2006, 11:42 AM
www.php.net/md5

Read and learn.

Microsoft
02-09-2006, 11:57 AM
mysql_query("INSERT INTO members SET name='{$HTTP_POST_VARS['username']}', creds='{$HTTP_POST_VARS['creds']}', password='{$HTTP_POST_VARS['password']}'")

Change to:
$name = $_POST['username'];
$creds = $_POST['creds'];
$pass = md5($_POST['password']);
mysql_query("INSERT INTO members (`name` , `creds` , `password`) VALUES ('$name' , '$creds' , '$pass')");


Edit:
Remember to md5 it where you login by putting md5($_POST['whatever'])

MrStretch
02-09-2006, 12:08 PM
Thank you very much :-)
Ive figured it out now.

Microsoft
02-09-2006, 12:15 PM
No problemo.

Want to hide these adverts? Register an account for free!