MD5 Encrypting Password


The MD5 Message-Digest Algorithm is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value. Specified in RFC 1321, MD5 has been employed in a wide variety of security applications, and is also commonly used to check data integrity. MD5 was designed by Ron Rivest in 1991 to replace an earlier hash function, MD4. An MD5 hash is typically expressed as a hexadecimal number, 32 digits long.(Wiki)

Using md5(); function to make your login system more secure.
Syntax

string md5 ( string $str [, bool $raw_output = false ] )

( PHP )
Return Values: Returns the hash as a 32-character hexadecimal number.
Overview
Look at these two databases, it’s the same person and same info, the first one we don’t encrypt his password, but the second one we encrypted his password.
encrypted password
When you encryte “john856” using this code, you’ll see the result
“ad65d5054042fda44ba3fdc97cee80c6”

This is not a random result, everytime you encrypt the same password you will get the same result.

<?php
$password="john856";
$encrypt_password=md5($password);
echo $encrypt_password;
?>

Example – Login

This is an example Login with encrypted password, but don’t forget to encrypt password and insert into database when your user sign up.

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// encrypt password 
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);

You can learn to create login system here

,

Trackbacks/Pingbacks

  1. How to creat PHP Login Script | Free Online Tutorials - August 8, 2012

    […] Read more about encrypting password here […]

Leave a Reply