SHARE
TWEET

Untitled

a guest Oct 18th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Model
  4. {
  5.     private $databaseConnection;
  6.  
  7.     public $message = "";
  8.     public $usernameVariable = "";
  9.  
  10.     public function __construct()
  11.     {
  12.         $this->databaseConnection = mysqli_connect(ServerConfig::$dbServerName, ServerConfig::$dbUsername, ServerConfig::$dbPassword, ServerConfig::$dbName);
  13.     }
  14.  
  15.     public function usernameExist($username)
  16.     {
  17.         $sqlSearchString = "SELECT * FROM users WHERE BINARY user_username='$username';";
  18.  
  19.         $result = mysqli_query($this->databaseConnection, $sqlSearchString);
  20.  
  21.         // If user was found, result is larger than 0
  22.         $resultCheck = mysqli_num_rows($result);
  23.         if ($resultCheck > 0) {
  24.             return true;
  25.         }
  26.     }
  27.  
  28.     public function saveUserToDb($username, $password)
  29.     {
  30.         $passwordHash = password_hash($password, PASSWORD_BCRYPT);
  31.         $cookiePasswordHash = password_hash($password, PASSWORD_BCRYPT);
  32.  
  33.         $sqlSearchString = "INSERT INTO users (user_username, user_pwd, user_cookiePassword) VALUES ('$username', '$passwordHash', '$cookiePasswordHash');";
  34.         mysqli_query($this->databaseConnection, $sqlSearchString);
  35.     }
  36.  
  37.     private function getUser($username)
  38.     {
  39.         $sqlSearchString = "SELECT * FROM users WHERE BINARY user_username='$username';";
  40.        
  41.         $result = mysqli_query($this->databaseConnection, $sqlSearchString);
  42.  
  43.         // If user was found, result is larger than 0
  44.         $resultCheck = mysqli_num_rows($result);
  45.         if ($resultCheck > 0) {
  46.             return mysqli_fetch_assoc($result);
  47.         }
  48.     }
  49.  
  50.     public function verifyPassword($username, $password)
  51.     {
  52.         $databaseUser = $this->getUser($username);
  53.  
  54.         return password_verify($password, $databaseUser['user_pwd']);
  55.     }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top