PHP - Simple Password Encryptor

In this tutorial we will create a Simple Password Encryptor Using php. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding...

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.         <head>
  4.                 <meta charset="UTF-8" name="viewport" content="width=device-width, intial-scale=1" />
  5.                 <link rel="stylesheet" name="viewport" href="css/bootstrap.css"/>
  6.         </head>
  7. <body>
  8.         <nav class="navbar navbar-default">
  9.                 <div class="container-fluid">
  10.                         <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11.                 </div>
  12.         </nav>
  13.         <div class="col-md-3"></div>
  14.         <div class="col-md-6 well">
  15.                 <h3 class="text-primary">PHP - Simple Password Encryptor</h3>
  16.                 <hr style="border-top:1px dotted #ccc;"/>
  17.                 <div class="col-md-2"></div>
  18.                 <div class="col-md-8">
  19.                         <form action="" method="POST">
  20.                                 <div class="form-group">
  21.                                         <input type="text" placeholder="Enter your password" name="password" class="form-control" required="required"/>
  22.                                 </div>
  23.                                 <div class="form-group">
  24.                                         <label>Select an encryptor</label>
  25.                                         <select name="encryptor" required="required" class="form-control">
  26.                                                 <option value="">Select an option</option>
  27.                                                 <option value="md5">md5</option>
  28.                                                 <option value="sha1">sha1</option>
  29.                                                 <option value="ripemd160">ripemd160</option>
  30.                                                 <option value="haval160,4">haval160,4</option>
  31.                                                 <option value="sha256">sha256</option>
  32.                                         </select>
  33.                                 </div>
  34.                                 <h4 class="text-success" style="word-wrap:break-word;"><?php include 'encrypt.php'?></h4>
  35.                                 <center><button name="encrypt" class="btn btn-primary">Encrypt</button></center>
  36.                         </form>
  37.                 </div>
  38.         </div>
  39. </body>
  40. </html>

Creating the Main Function

This code contains the main function of the application. This code will encrypt your password automatically. To do this just copy and write these block of codes as shown below inside the text editor, then save it as encrypt.php.
  1. <?php
  2.         if(ISSET($_POST['encryptor'])){
  3.                 $encryptor  = $_POST['encryptor'];
  4.                 $password = $_POST['password'];
  5.                
  6.                 switch($encryptor ){
  7.                         case "md5":
  8.                                 echo hash("md5", $password);
  9.                                 break;
  10.                         case "sha1":
  11.                                 echo hash("sha1", $password);
  12.                                 break;
  13.                         case "ripemd160":
  14.                                 echo hash("ripemd160", $password);
  15.                                 break;
  16.                         case "haval160,4":
  17.                                 echo hash("haval160,4", $password);
  18.                                 break;
  19.                         case "sha256":
  20.                                 echo hash("sha256", $password);
  21.                                 break; 
  22.                 }
  23.         }
  24. ?>
There you have it we successfully created a Simple Password Encryptor using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment