Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create an account in the database.
- * @param $account
- * @return Account|null
- */
- public function create($account)
- {
- $stmt = $this->db->prepare("SELECT count(*) FROM account WHERE username = ?");
- $stmt->bind_param("s", $account->username);
- $stmt->execute();
- $stmt->bind_result($count);
- $stmt->fetch();
- $stmt->close();
- if($count > 0)
- return null;
- if($this->validate($account))
- {
- $stmt = $this->db->prepare("INSERT INTO account(username, password, email, phone, token, reset_time, role) VALUES (?, ?, ?, ?, ?, ?, ?)");
- $hashedPassword = password_hash($account->password, PASSWORD_DEFAULT);
- $stmt->bind_param("sssssis", $account->username, $hashedPassword, $account->email, $account->phone, $account->token, $account->reset_time, $account->role);
- $stmt->execute();
- $stmt->close();
- return new Account($account->username, $hashedPassword, $account->email, $account->phone, $account->token, $account->reset_time, $account->role);
- }
- else
- {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement