Quantcast
Channel: webdevelopplus.com » PHP Tutorial
Viewing all articles
Browse latest Browse all 6

PHP Code – Encrypting Password Using Md5()

$
0
0

Encrypting Password in PHP Using md5() Function

When a User Login and Register to its Account Then Password is Saved into the Database or Any Record But What Happens When Someone Sees Your Password From the Database In That Case Your Password is not Safe. So That’s Why we Use md5() Function or md5 Encryption to Password. It is a One Way Encryption Which cannot be Decrypt. So That’s Why We use md5 encryption.

Here in This Code we get the encrypted Password Which is Stored in The Text File Then Check the Password and Then Goto It’s UserPanel.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
if(isset($_POST['user_password'])&& !empty($_POST['user_password']))
{
$user_password = md5($_POST['user_password']);
$filename ='hash.txt'; //This is the file where password is stored
$handle =fopen($filename,'r');
$file_password = fread($handle,filesize($filename));
if(user_password==$file_password) //Here We Compare the Password From the File.
{
echo'Password ok!';
}
else
{
echo'Incorrect Password.';
}
}
else
{
echo'Please enter a password.';
}
?>
<form action ="md5.php" method="POST">
Password:<input type="password" name="user_password"><br><br>
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['user_password'])&& !empty($_POST['user_password']))
{
$user_password = md5($_POST['user_password']);
$filename ='hash.txt'; //This is the file where password is stored
$handle =fopen($filename,'r');
$file_password = fread($handle,filesize($filename));
if(user_password==$file_password) //Here We Compare the Password From the File.
{
echo'Password ok!';
}
else
{
echo'Incorrect Password.';
}
}
else
{
echo'Please enter a password.';
}
?>
<form action ="md5.php" method="POST">
Password:<input type="password" name="user_password"><br><br>
<input type="submit" value="Submit">
</form>

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images