Log In and Registration Form using MD5 in PHP/MySQL

In this tutorial, we are going to learn how to create Log In and Registration Form using MD5 Encryption in PHP/MySQL. The features of this simple program, it has a registration form for a user and it has an input validation that the empty field is not allowed same with the login form and the password are encrypted using MD5. Hope that this source code will help you in your future system.

Creating Markup for Registration Form

It contains two input field and one button as shown in the image below. Result The source code of the registration form.
  1. <div class="row-fluid">
  2. <div class="span6" style="margin-left: 220px;">
  3. <div class="alert alert-success">Register User</div>
  4. <form class="form-horizontal" method="POST">
  5. <div class="control-group">
  6. <label class="control-label" for="inputEmail">Username</label>
  7. <div class="controls">
  8. <input type="text" id="inputEmail" name="username" placeholder="Username" required>
  9. </div>
  10. </div>
  11. <div class="control-group">
  12. <label class="control-label" for="inputPassword">Password</label>
  13. <div class="controls">
  14. <input type="text" id="inputPassword" name="password" placeholder="Password" required>
  15. </div>
  16. </div>
  17. <div class="control-group">
  18. <div class="controls">
  19. <button type="submit" name="register" class="btn btn-success">Save</button>
  20. </div>
  21. </div>
  22. </form>
  23. </div>
  24. <?php
  25. if (isset($_POST['register'])){
  26. $username=$_POST['username'];
  27. $password=md5($_POST['password']);
  28.  
  29. mysql_query("insert into user (username,password) values('$username','$password')")or die(mysql_error());
  30. header('location:index.php');
  31. }
  32. ?>
  33. </div>

Creating Markup for Log In Form

Also, it contains two input field and one button as shown in the image below. Result The source code of the login form.
  1. <div class="row-fluid">
  2. <div class="span6" style="margin-left: 220px;">
  3. <div class="alert alert-success">Log In</div>
  4. <form class="form-horizontal" method="POST">
  5. <div class="control-group">
  6. <label class="control-label" for="inputEmail">Username</label>
  7. <div class="controls">
  8. <input type="text" id="inputEmail" name="username" placeholder="Username" required>
  9. </div>
  10. </div>
  11. <div class="control-group">
  12. <label class="control-label" for="inputPassword">Password</label>
  13. <div class="controls">
  14. <input type="password" name="password" id="inputPassword" placeholder="Password" required>
  15. </div>
  16. </div>
  17. <div class="control-group">
  18. <div class="controls">
  19. <button type="submit" name="login" class="btn btn-primary">Login</button>
  20. </div>
  21. <br>
  22. <?php
  23. if (isset($_POST['login'])){
  24. $username=$_POST['username'];
  25. $password=md5($_POST['password']);
  26.  
  27. $login=mysql_query("select * from user where username='$username' and password='$password'")or die(mysql_error());
  28. $count=mysql_num_rows($login);
  29.  
  30. if ($count > 0){
  31. header('location:home.php');
  32. }else{ ?>
  33. <div class="alert alert-error">Error login! Please check your username or password</div>
  34. <?php
  35. }}
  36. ?>
  37. </div>
  38. </form>
  39. </div>
  40. </div>

Output

Lists of a user after registering to the registration form as shown in the image below. Resultusername: admin password: admin username: user password: user username: sourcecodester password: sourcecodester Hope that this source code will help you in your future system. 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