Skip to main content

PHP - Simple Register With md5


In this tutorial we will create a Simple Register With md5 using PHP. This code can encrypt the user password information when the checkbox is checked. The code use a special php built-in function md5() a very strong encrypting tool that encrypt the user password by just passing a string as a parameter.

We will be using PHP as a scripting language and interpreter that is used primarily on any webserver including xamp, wamp, etc. It is being use to any famous websites and it has a modern technology that can easily be use by the next generation.

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 Database

Open your database web server then create a database name in it db_reg_md5, after that click Import then locate the database file inside the folder of the application then click ok.
tut1

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.

  1. <?php
  2. $conn = mysqli_connect("localhost", "root", "", "db_reg_md5");
  3.  
  4. if(!$conn){
  5. die("Error: Failed to connect to database!");
  6. }
  7. ?>

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 your text editor, then save it as shown below.
index.php

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" 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 Register With md5</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-3">
  18. <a href="user.php">List of users</a>
  19. </div>
  20. <div class="col-md-6">
  21. <form method="POST" action="">
  22. <div class="form-group">
  23. <label>Username</label>
  24. <input type="text" name="username" maxlength="50" class="form-control" required="required"/>
  25. </div>
  26. <div class="form-group">
  27. <label>Password</label>
  28. <input type="password" name="password" maxlength="12" class="form-control" required="required"/>
  29. </div>
  30. <div class="form-group">
  31. <label>Firstname</label>
  32. <input type="text" name="firstname" class="form-control" required="required"/>
  33. </div>
  34. <div class="form-group">
  35. <label>Lastname</label>
  36. <input type="text" name="lastname" class="form-control" required="required"/>
  37. </div>
  38. <label><input type="checkbox" name="encrypt" value="md5"/>Encrypt with md5</label>
  39. <br />
  40. <?php include 'register.php'?>
  41. <center><button class="btn btn-primary" name="save"><span class="glyphicon glyphicon-save"></span> Register</button></center>
  42. </form>
  43. </div>
  44. </div>
  45. </body>
  46. </html>

user.php

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" 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 Register With md5</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-3">
  18. <a href="index.php">Registration Form</a>
  19. </div>
  20. <div class="col-md-9">
  21. <div class="table-responsive ">
  22. <table class="table table-bordered">
  23. <thead class="alert-info">
  24. <tr>
  25. <th>Firstname</th>
  26. <th>Lastname</th>
  27. <th>Username</th>
  28. <th>Password</th>
  29. </tr>
  30. </thead>
  31. <tbody>
  32. <?php
  33. require'conn.php';
  34. $query=mysqli_query($conn, "SELECT * FROM `user`") or die(mysqli_error());
  35. while($fetch=mysqli_fetch_array($query)){
  36. ?>
  37. <tr>
  38. <td><?php echo $fetch['firstname']?></td>
  39. <td><?php echo $fetch['lastname']?></td>
  40. <td><?php echo $fetch['username']?></td>
  41. <td><?php echo $fetch['password']?></td>
  42. </tr>
  43. <?php
  44. }
  45. ?>
  46. </tbody>
  47. </table>
  48. </div>
  49. </div>
  50. </div>
  51. </body>
  52. </html>

Creating the Main Function

This code contains the main function of the application. This code will allow the user to encrypt the password with the md5 encrypted protection. To do this just kindly write these block of codes inside the text editor, then save it as register.php.

  1. <?php
  2. require_once 'conn.php';
  3.  
  4. if(ISSET($_POST['save'])){
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7. $firstname = $_POST['firstname'];
  8. $lastname = $_POST['lastname'];
  9.  
  10. if(ISSET($_POST['encrypt'])){
  11. $password = md5($password);
  12. }
  13.  
  14. mysqli_query($conn, "INSERT INTO `user` VALUES('', '$username', '$password', '$firstname', '$lastname')") or die(mysqli_error());
  15.  
  16. echo "<center><label class='text-success'>Successfully registered!</label></center>";
  17. }
  18. ?>

There you have it we successfully created a Simple Register With md5 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!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.