Hello readers,today i am here with another superb tutorial of php. Well we will encrypt a password in php. The function md5() will be used to encrypt a password. Password is the thing that should be confidential. In online world,password is much important factor. You should never tell your password to others. You should keep changing it at particular time interval. We will  write a code to encrypt a password in php using md5

The word encrypt suggest itself ! If you are familiar with information security then you may know about it. Encryption is technique by which you are protecting your data which is going to be sent. When you register or sign up somewhere at any online website,there is one database where your all information is stored. In that database your password will not be in a simple form.It will be in some encrypted form so that if the database is leaked somewhere no one can use the original password. 
In php this type of encryption is done by md5() function. Actually md5 is one type of hashing algorithm by which hashing code is generated and it is attached to the original data in encrypted form.

Let’s go to the source code to encrypt a password in php via md5


<?php

if(isset($_POST['txt'])&&isset($_POST['pass']))
{

$user=$_POST['txt'];
$password=$_POST['pass'];
if(!empty($_POST['txt'])&&!empty($_POST['pass']))
{
$encrypt=md5($password);

echo "USER NAME: ".$user."<br>";
echo "PASSWORD: ".$password."<br>";
echo "Encrypted password :".$encrypt."<br>";
}
else
{
echo "Please enter the value";
}
}
?>
<hr>
<form action="md.php" method="POST">
Username:<input type="text" name="txt"><br><br>
Password:<input type="password" name="pass"><br>
<input type="submit" value="Submit">
</form>

Output of encrypt password via md5 php program 

How to  encrypt a password in php using md5

Logic of password encryption in php via md5

Well,it works simple. First of all we made one form having username and password entity. As soon as you enter the detail and click submit button,the data will be posted to php script . Then after setting it to the some other variables ,We took one variable and inside which we stored value of password in encrypted form. ( md5(value)).To get the data we wrote echo statement.Finally we encrypted a password in php using md5

Is md5 secure ?

Yes,it is secure. It’s one way encryption algorithm, You can not generate the original password from that hash code. So there will not be any problem if the database of any system leaked by someone. Yeah it may be possible to get the original data if attacker will apply some attacks .But it will be complicated .Do share this program for encrypt a password in php with md5.
So i hope you all like this ,keep connected and do like our fb page to support.

By jigar

Leave a Reply

Your email address will not be published. Required fields are marked *