Sample PHP code to store and verify the encrypted password

Sample PHP code to Store and verify the encrypted password
Here Base64-encoded and decode function is used to store and retrieve the password.

Base64 encoded function is commonly used when there is a need to encode binary data that needs to be stored and transferred over media that is designed to deal with textual data. It is commonly used in a number of applications, including email via MIME, and storing complex data in XML.

Base64 decoded function is used to yield the original content (decoded content) from the encoded content.

The Base64-encoded function work process involves

  1. Password change into random letters, numbers and/or characters.
  2. Base64-encoded data takes about 33% more space than the original data.

 

Encryption

Sample PHP code for Store and verify the encrypted password

To store the password
$Link = mysql_connect ("localhost","root","") or
die('Databse not connected'.mysql_error());
mysql_select_db ("Test", $Link);
$username=$_REQUEST['urname'];
$password=$_REQUEST ['pword'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$password1=base64_encode(gzdeflate($password));
$query  ="INSERT INTO Reg_test(username,password,email,phone)
VALUES('$username','$password1','$email','$phone')";
To verify the password

$password1=base64_encode(gzdeflate($password));
$selquery="select * from Reg_test where username='$username'";
$result=mysql_query($selquery,$Link);
<p style="text-align: left;">while ($row = mysql_fetch_array($result,
MYSQL_ASSOC))
{
if($username!=$row['username'] and $password1!=$row['password'])
{
?>
<script lang="javascript">
alert("Username Didn't Match Please Verify");
window.location.href="[Redirect URL]";
</script>
<?php
}
else
{
$pss=gzinflate(base64_decode($row['password']));
echo $username=$row['username']."&amp;lt;br/&amp;gt;";
echo $password=$pss."&amp;lt;br/&amp;gt;";
echo $email=$row['email']."&amp;lt;br/&amp;gt;";
echo $Phone=$row['phone']."&amp;lt;br/&amp;gt;";
}
}

Sample PHP code for creating forgot password feature in any website

About

Smart Guy/ PHP Developer

Posted in Php Tagged with: , , ,