PHP - Simple Register With md5

Submitted by: 
Language: 
Visitors have accessed this post 289 times.

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="<a href="https://sourcecodester.com">Sourcecodester</a>
  11. " rel="nofollow">https://sourcecodester.com">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">PHP - Simple Register With md5</h3>
  17. <hr style="border-top:1px dotted #ccc;"/>
  18. <div class="col-md-3">
  19. <a href="user.php">List of users</a>
  20. </div>
  21. <div class="col-md-6">
  22. <form method="POST" action="">
  23. <div class="form-group">
  24. <label>Username</label>
  25. <input type="text" name="username" maxlength="50" class="form-control" required="required"/>
  26. </div>
  27. <div class="form-group">
  28. <label>Password</label>
  29. <input type="password" name="password" maxlength="12" class="form-control" required="required"/>
  30. </div>
  31. <div class="form-group">
  32. <label>Firstname</label>
  33. <input type="text" name="firstname" class="form-control" required="required"/>
  34. </div>
  35. <div class="form-group">
  36. <label>Lastname</label>
  37. <input type="text" name="lastname" class="form-control" required="required"/>
  38. </div>
  39. <label><input type="checkbox" name="encrypt" value="md5"/>Encrypt with md5</label>
  40. <br />
  41. <?php include 'register.php'?>
  42. <center><button class="btn btn-primary" name="save"><span class="glyphicon glyphicon-save"></span> Register</button></center>
  43. </form>
  44. </div>
  45. </div>
  46. </body>
  47. </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="<a href="https://sourcecodester.com">Sourcecodester</a>
  11. " rel="nofollow">https://sourcecodester.com">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">PHP - Simple Register With md5</h3>
  17. <hr style="border-top:1px dotted #ccc;"/>
  18. <div class="col-md-3">
  19. <a href="index.php">Registration Form</a>
  20. </div>
  21. <div class="col-md-9">
  22. <div class="table-responsive ">
  23. <table class="table table-bordered">
  24. <thead class="alert-info">
  25. <tr>
  26. <th>Firstname</th>
  27. <th>Lastname</th>
  28. <th>Username</th>
  29. <th>Password</th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. <?php
  34. require'conn.php';
  35. $query=mysqli_query($conn, "SELECT * FROM `user`") or die(mysqli_error());
  36. while($fetch=mysqli_fetch_array($query)){
  37. ?>
  38. <tr>
  39. <td><?php echo $fetch['firstname']?></td>
  40. <td><?php echo $fetch['lastname']?></td>
  41. <td><?php echo $fetch['username']?></td>
  42. <td><?php echo $fetch['password']?></td>
  43. </tr>
  44. <?php
  45. }
  46. ?>
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>
  51. </div>
  52. </body>
  53. </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!


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.