Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. // define the mysql settings
  4. define("DB_SERVER", "localhost");
  5. define("DB_USERNAME","username");
  6. define("DB_PASSWORD", "password");
  7. define("DB_NAME", "database");
  8.  
  9. // setting MySQL table and configuration
  10. $connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME) or die ("Cannot connect");
  11.  
  12. // read input from user
  13. $username = $_POST["username"];
  14. $password = $_POST["password"];
  15.  
  16. if(isset($_POST["login"])) {
  17. if (empty($_POST["username"]) || empty($_POST["password"])) {
  18. echo "Fill the username and the password text field";
  19. } else {
  20. // protect from SQL Injection
  21. $username = stripslashes($username);
  22. $password = stripslashes($password);
  23. $username = mysqli_real_escape_string($connection, $username);
  24. $password = mysqli_real_escape_string($connection, $password);
  25. $password = md5($password);
  26.  
  27. // execute the query
  28. $query = "select * from account where username = '$username' and password = '$password'";
  29. $result = mysqli_query($connection, $query) or die (mysql_error());
  30. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  31. if (mysqli_num_rows($result) == 1) {
  32. if ($row["username"] == $username && $row["password"] == $password) {
  33. echo "LOGIN SUKSES";
  34. }
  35. } else {
  36. echo "LOGIN GAGAL";
  37. }
  38. }
  39. }
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement