Advertisement
Atheuz

Untitled

Jun 14th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1.     /**
  2.      * Create an account in the database.
  3.      * @param $account
  4.      * @return Account|null
  5.      */
  6.     public function create($account)
  7.     {
  8.         $stmt = $this->db->prepare("SELECT count(*) FROM account WHERE username = ?");
  9.         $stmt->bind_param("s", $account->username);
  10.         $stmt->execute();
  11.         $stmt->bind_result($count);
  12.         $stmt->fetch();
  13.         $stmt->close();
  14.  
  15.         if($count > 0)
  16.             return null;
  17.  
  18.         if($this->validate($account))
  19.         {
  20.             $stmt = $this->db->prepare("INSERT INTO account(username, password, email, phone, token, reset_time, role) VALUES (?, ?, ?, ?, ?, ?, ?)");
  21.             $hashedPassword = password_hash($account->password, PASSWORD_DEFAULT);
  22.             $stmt->bind_param("sssssis", $account->username, $hashedPassword, $account->email, $account->phone, $account->token, $account->reset_time, $account->role);
  23.             $stmt->execute();
  24.             $stmt->close();
  25.             return new Account($account->username, $hashedPassword, $account->email, $account->phone, $account->token, $account->reset_time, $account->role);
  26.         }
  27.         else
  28.         {
  29.             return null;
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement