Advertisement
Guest User

Untitled

a guest
Oct 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4. $host = "localhost";
  5. $user = "root";
  6. $pass = "";
  7. $data = "skyhigh";
  8.  
  9. $con = new mysqli($host, $user, $pass, $data);
  10.  
  11. if($con->connect_errno)
  12. {
  13. printf("Connect failed: %s\n", $con->connect_error);
  14. }
  15.  
  16. $action = $_GET['action'];
  17.  
  18. $username = $con->real_escape_string($_GET['username']);
  19. $password = $con->real_escape_string($_GET['password']);
  20. $newpassword = $con->real_escape_string($_GET['newpassword']);
  21.  
  22.  
  23. //Enctrypt passwords START
  24. $encpassword = hash('sha256', $password);
  25. $encnewpassword = hash('sha256', $newpassword);
  26. //Encrypt passwords END
  27.  
  28.  
  29. if(!$action)
  30. {
  31. echo "Please enter an action.";
  32. }
  33. else
  34. {
  35. if($action == "register")
  36. {
  37.  
  38.  
  39. $result = mysql_query("SELECT * FROM users WHERE username = " . $username);
  40. if(mysql_num_rows($result) == 0) {
  41. // row not found, do stuff...
  42.  
  43.  
  44. if($query = $con->query("INSERT INTO users (id,username,password) VALUES ('$username','$encpassword')"))
  45. {
  46. echo "1";
  47. }
  48. else
  49. {
  50. echo "0";
  51. }
  52. }
  53. else
  54. {
  55. echo "0";
  56. }}
  57.  
  58.  
  59. else if($action == "login")
  60. {
  61. $query = $con->query("SELECT * FROM users WHERE username = '$username' and password = '$encpassword'");
  62. $cnt = $query->num_rows;
  63.  
  64. if($cnt > 0)
  65. {
  66. echo "1";
  67. }
  68. else
  69. {
  70. echo "0";
  71. }
  72. }
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement