Advertisement
GrgBastin

Untitled

Mar 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. class users
  3. {
  4. protected $db = null;
  5.  
  6. public function __construct($db){
  7. $this->db = $db;
  8. }
  9.  
  10. public function registerUser($email, $password){
  11.  
  12. $encryptedPass = password_hash($password, PASSWORD_DEFAULT);
  13. //Insert DB
  14. $query = "INSERT INTO users (user_email, user_password) VALUES (:email, :password)";
  15. $pdo = $this->db->prepare($query);
  16. $pdo->bindParam(':email', $email);
  17. $pdo->bindParam(':password', $encryptedPass);
  18. $pdo->execute();
  19.  
  20. return $this->db->lastInsertId();
  21. }
  22.  
  23. public function getUser($userid){
  24. //Let's get the users information
  25. $query = "SELECT * FROM users WHERE user_id = :userid";
  26. $pdo = $this->db->prepare($query);
  27. $pdo->bindParam(':userid', $userid);
  28. $pdo->execute();
  29.  
  30. return $pdo->fetch(PDO::FETCH_ASSOC);
  31. }
  32.  
  33. public function checkUser($email, $password){
  34. //lets get user
  35. $query = "SELECT * FROM users WHERE user_email = :email";
  36. $pdo = $this->db->prepare($query);
  37. $pdo->bindParam(':email', $email);
  38. $pdo->execute();
  39.  
  40. $user = $pdo->fetch(PDO::FETCH_ASSOC);
  41.  
  42. if(empty($user)){
  43. return false;
  44. }else if(password_verify($password, $user['user_password'])){
  45. return $user;
  46. }else{
  47. return false;
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement