Easy MD5 password Encryption Decryption Example using php



Here are the main lines of code the encrypt the password


PART 1 Password Encryption 
//get the password in variable
$password = isset($_GET['password']) ? mysql_real_escape_string($_GET['password']) :  "";

//here n5tZoJDknmUgY6LR21FFr4SAoQK8ACajoO3egV0I2JU4Uu8ihuk20hgm is the hashkey do save it
//encrypt using the below syntax then insert into database

 $password = md5("n5tZoJDknmUgY6LR21FFr4SAoQK8ACajoO3egV0I2JU4Uu8ihuk20hgm".$password."");

==========================================================

Here below is the full code I used

<?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); ?>
<?php header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT'); ?>

<?php

//echo "hi there";


include_once('confi.php');
error_reporting(E_ALL);
$name = isset($_GET['name']) ? mysql_real_escape_string($_GET['name']) :  "";
$email = isset($_GET['email']) ? mysql_real_escape_string($_GET['email']) :  "";
$password = isset($_GET['password']) ? mysql_real_escape_string($_GET['password']) :  "";
    $password = md5("n5tZoJDknmUgY6LR21FFr4SAoQK8ACajoO3egV0I2JU4Uu8ihuk20hgm".$password."");
$uid = isset($_GET['uid']) ? mysql_real_escape_string($_GET['uid']) :  "";
    $idshop = isset($_GET['idshop']) ? mysql_real_escape_string($_GET['idshop']) :  "";
    if(!empty($uid)){
        $query = "SELECT * FROM ps_customer WHERE email = '$email' AND id_shop='$idshop'";
        $qur = mysql_query($query);
        $existCount = mysql_num_rows($qur); // count the row nums
if ($existCount == 0) { // evaluate the count
//echo "Proceed";
 
    $securekey = md5(uniqid(rand(), true));
   
     $insertstatement = "INSERT INTO `ps_customer` (`id_customer`, `id_shop_group`, `id_shop`, `id_gender`, `id_default_group`, `id_lang`, `id_risk`, `company`, `siret`, `ape`, `firstname`, `lastname`, `email`, `passwd`, `last_passwd_gen`, `birthday`, `newsletter`, `ip_registration_newsletter`, `newsletter_date_add`, `optin`, `website`, `outstanding_allow_amount`, `show_public_prices`, `max_payment_days`, `secure_key`, `note`, `active`, `is_guest`, `deleted`, `date_add`, `date_upd`) VALUES (NULL, '1', '$idshop', '1', '3', '1', '0', NULL, NULL, NULL, '', '$name', '$email', '$password',NOW(), '2000-01-01', '0', NULL, '0000-00-00 00:00:00', '0', NULL, '0.000000', '0', '0', '$securekey', NULL, '1', '0', '0', NOW(), NOW());";
  //  echo $insertstatement;
    $query123 = mysql_query($insertstatement);
   
   
    $selectquery = "SELECT MAX(id_customer) a FROM `ps_customer`;";
  //  echo "$selectquery";
   
     $query1 = mysql_query($selectquery);
  //  echo"test" ;
    while($row = mysql_fetch_array($query1)) {
       
      $id_customer = $row['a'];
       //  $id_customer1 = int($id_customer) + 1;
    }
   // echo "'.$id_customer.' i am first";
    //$id_customer1 = $id_customer + 1;
   // echo "$id_customer1";

    $insert2 = "INSERT INTO `ps_customer_group` (
`id_customer` ,
`id_group`
)
VALUES (
'$id_customer',  '3'
);";
   
   //echo "$insert2";
    $query123 = mysql_query($insert2);
    $true = "true";
    $result[] = array("status" => $true,"id_customer" => $id_customer);
   $json = $result;

   
}else{
    $false = "false";
//echo "Your login session data already exists in the database.";
    $result[] = array("status" => $false);
   $json = $result;
   
}
}
@mysql_close($conn);
/* Output header */
header('Content-type: application/json');
echo json_encode($json);


//echo "$query i m qwedrdfrd";
//echo "$existCount i m exist";
//echo "$insertstatement";



PART 2 Password Decryption 

Below is an example of login where we select the user from database here MD5 Decryption is used.

<?php
// Include confi.php
include_once('confi.php');
$shopid = isset($_GET['shopid']) ? mysql_real_escape_string($_GET['shopid']) :  "";
$email = isset($_GET['email']) ? mysql_real_escape_string($_GET['email']) :  "";
$passwd1 = isset($_GET['passwd']) ? $_GET['passwd'] :  "";
if(!empty($email)){
        $mysql = "select id_customer,firstname,lastname,passwd,email from ps_customer where email = '".$email."' AND id_shop='".$shopid."'";
       // echo "$mysql";
$qur = mysql_query($mysql);
$result =array();
while($r = mysql_fetch_array($qur)){
extract($r);
            //echo "$r";
$passwd1 = md5("n5tZoJDknmUgY6LR21FFr4SAoQK8ACajoO3egV0I2JU4Uu8ihuk20hgm".$passwd1."");

if($passwd1 ==$passwd){

 $result[] = array("id_customer" => $id_customer, "firstname" => $price,"lastname" => $lastname, 'passwd' => $passwd, 'email' => $email);
 }else{}}
$json = $result;
}else{
$json = array("status" => 0, "msg" => "User ID not define");
}
@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json);


Joel

Joel Fernandes,I am a Very Smart,Innovative Creative and One of the Best Webdevelopers.I am an expert in Webdevelopment.My other interest include Cars and Vehicles.My desire is to be the best and serve you with the best information I have .I will always share all my tips and tricks on this website and provide you with the best themes so that your life may be simpler.Keep visiting www.joelwebsites.com for the best website related ,tips and tricks and news.Meet me on FaceBook

1 comment:

  1. Security is the basis for every successful IT project, which has a user base. I often seek the help of professional software developers http://www.nixsolutions.com/departments/php/. Project security is one of the important parts that can ruin your reputation in case of error or hacking.

    ReplyDelete