Thursday, April 10, 2014

Encrypt Password using md5() in PHP

Syntax

Description: Calculate the MD5 hash of the string. md5() is used to secure your password more secure.
$pwd="Vinoth";
md5($pwd);

HTML Code

<form name="encrypt" action="#" method="post">
  <p>
    <label for="Name">Name:</label>
    <input type="text" name="name" />
  </p>
  <p>
    <label for="password">Password:</label>
    <input type="password" name="password" />
  </p>
  <p>
    <input type="submit" name="submit" value="Encrypt" />
  </p>
</form>

PHP Code

<?php
if(isset($_POST['submit'])) {

$name=$_POST['name'];
$pwd=$_POST['password'];

//Before encryption
echo "Before Encryption : ".$pwd;
echo "<br>";
//After encryption
$encryptpwd=md5($pwd);
echo "After Encryption : ".$encryptpwd;

}
?>

1 comment:

  1. Only MD5 is not secure.
    Using a unique salt per user is a very good idea.

    ReplyDelete