Login using MD5 in PHP

We are going to create Login using MD5 in PHP. This source code will help you on how to create a simple login form with MD5 Encryption. It has input validation does not allow the user to enter in the home page if the form field was empty and password is being encrypted using the MD5. We have sample source code for the form field below. Take a look and kindly study the code. Then, try it.
  1. <form class="form-horizontal" method="POST">
  2. <div class="control-group">
  3. <label class="control-label" for="inputEmail">Username</label>
  4. <div class="controls">
  5. <input type="text" id="inputEmail" name="username" placeholder="Username" required>
  6. </div>
  7. </div>
  8. <div class="control-group">
  9. <label class="control-label" for="inputPassword">Password</label>
  10. <div class="controls">
  11. <input type="password" name="password" id="inputPassword" placeholder="Password" required>
  12. </div>
  13. </div>
  14. <div class="control-group">
  15. <div class="controls">
  16. <button type="submit" name="login" class="btn btn-primary">Login</button>
  17. </div>
  18. <br>
  19. <?php
  20. if (isset($_POST['login'])){
  21. $username=$_POST['username'];
  22. $password=md5($_POST['password']);
  24. $login=mysql_query("select * from user where username='$username' and password='$password'")or die(mysql_error());
  25. $count=mysql_num_rows($login);
  27. if ($count > 0){
  28. header('location:home.php');
  29. }else{ ?>
  30. <div class="alert alert-error">Error login! Please check your username or password</div>
  31. <?php
  32. }}
  33. ?>
  34. </div>
  35. </form>
Username : admin Password: admin


Result Hope that this simple source code will help you a lot. Thank you.

Add new comment