How to Convert Text in Sha1 using PHP/MySQL

In this article, we are going to learn how to Convert Text in Sha1 using PHP/MySQL. This simple program will demonstrate how to convert text in Sha1. Sha1 creates 160-bit (20-byte) hash value. Creating simple TextBox, buttons, and another TextBox for viewing the result of Sha1 to the form field as in the image below. Result Here's the source code of the image above.
  1.         <div style="border:2px solid blue; background:azure; width:500px; padding:20px;">
  2.                 <form method="post">
  3.                         <h2 style="color:blue; font-family:cursive;">Convert Text to Sha1</h2><br>
  4.                         <input type="text" name="convert" style="padding:5px; font-size:18px; width:245px; font-family:cursive;" placeholder="Type Anything . . . . ." autofocus="autofocus">
  5.                         <input type="submit" name="sha1_convertion" value="Convert" style="padding:5px; font-family:cursive; font-size:18px; color:blue; background:azure; border:1px solid blue; border-radius:4px; cursor:pointer;">
  6.                 </form>
  7.                 <br>
  8.                         <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  9.                         <input type="text" value="" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly><br><br>
  10.         </div>
For the conversion of text to Sha1, we are going to put this PHP query to the TextBox to view the result. This is the PHP query.
  1. <?php
  2.  
  3. if(isset($_POST['sha1_convertion'])){ echo sha1($_POST['convert']); }
  4.  
  5. ?>
Now, let's put to the TextBox.
  1. <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  2. <input type="text" value="<?php if(isset($_POST['sha1_convertion'])){ echo sha1($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly>
The complete source code.
  1. <!DOCTYPE html>
  2.         <title>Convert Text to Sha1</title>
  3. </head>
  4.  
  5.         <div style="border:2px solid blue; background:azure; width:500px; padding:20px;">
  6.                 <form method="post">
  7.                         <h2 style="color:blue; font-family:cursive;">Convert Text to Sha1</h2><br>
  8.                         <input type="text" name="convert" style="padding:5px; font-size:18px; width:245px; font-family:cursive;" placeholder="Type Anything . . . . ." autofocus="autofocus">
  9.                         <input type="submit" name="sha1_convertion" value="Convert" style="padding:5px; font-family:cursive; font-size:18px; color:blue; background:azure; border:1px solid blue; border-radius:4px; cursor:pointer;">
  10.                 </form>
  11.                 <br>
  12.                         <h2 style="color:blue; font-family:cursive;">Sha1 Result</h2><br>
  13.                         <input type="text" value="<?php if(isset($_POST['sha1_convertion'])){ echo sha1($_POST['convert']); } ?>" style="padding:5px; text-align:center; border:1px solid blue; color:blue; font-size:18px; background:azure; cursor:not-allowed; width:480px; " readonly><br><br>
  14.         </div>
  15.  
  16. </body>
  17. </html>
Here's the result of the full source code above. Result Hope that this tutorial will help you a lot. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment