Can anyone show me some sample code on how to use md5(); for passwords in a database. I would also like to see some sample code on how to check the md5(); for passwords in a database. The database I am using is MySQL.
So basically a log in script using md5();
I use a log in script now that I made, but I do not use md5(); and I really would like to for user passwords.
Thanks.
Using md5(); For Passwords
Moderator: General Moderators
-
bionicdonkey
- Forum Contributor
- Posts: 132
- Joined: Fri Jan 31, 2003 2:28 am
- Location: Sydney, Australia
- Contact:
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
Insert new user into db
After username/password are entered, check to see if they exist
Note: MD5 creates a hash, not an encryption. You cannot decode a hash, you can only compare it. However, a given string will give the same hash every time (md5("hello") == md5("hello") != md5("goodbye")).
Code: Select all
<?php
$password=md5("User Password");
$username="username";
$qry="INSERT INTO userTable(username,password) VALUES('".$username."', '".$password."')";
mysql_query($qry,$conn) or die("Unable to insert");
?>Code: Select all
<?php
$username=$_POST[username];
$password=md5($_POST[password]);
if($username!="" && $password!=""){ // just to make sure they are not blank
$qry_login="SELECT * FROM userTable WHERE username='".$username."' AND password='".$password."'";
$result=mysql_query($qry_login, $conn) or die("username fail");
}
?>