Advertisement
Guest User

Untitled

a guest
Dec 13th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'connection.php';
  4. header('Content-Type: application/json ');
  5.  
  6. class User {
  7.  
  8. private $db;
  9. private $connection;
  10.  
  11. function _construct() {
  12. $this->db = new DB_connection();
  13. $this->connection = $this->db->get_connection();
  14. }
  15.  
  16. public function does_user_exist($username,$password) {
  17.  
  18. $query = "Select * from users where username = '$username' and password = '$password' ";
  19. $result = mysqli_query($this->connection, $query);
  20. if(mysqli_num_rows($result) > 0) {
  21. $json['success'] = ' Welcome ' .$username;
  22. echo json_encode($json);
  23. mysqli_close($this->connection);
  24.  
  25. } else {
  26.  
  27. $query = "Insert into users(username,password) values ('$username',$password');"
  28. $is_inserted = mysqli_query($this->connection, $query);
  29. if ($is_inserted == 1) {
  30. $json['success'] = ' Account created, welcome '.$username;
  31.  
  32. } else {
  33. $json['error'] = ' Wrong Password ';
  34.  
  35. }
  36. echo json_encode($json);
  37. mysqli_close($this->connection);
  38. }
  39. }
  40. }
  41.  
  42. $user = new User();
  43. if (isset($_POST['username'],$_POST['password'])) {
  44. $username = $_POST['username'];
  45. $username = $_POST['password'];
  46.  
  47. if (!empty($username) && !empty($password)) {
  48.  
  49. $encrypted_password = md5($password);
  50. $user -> does_user_exist($username,$encrypted_password);
  51.  
  52. } else {
  53. echo json_encode(" You must fill both fields ");
  54.  
  55. }
  56.  
  57.  
  58. }
  59.  
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement