Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getCurrentUserId(){
- $username = $_SESSION['username'];
- $statement = self::$db->prepare("SELECT id FROM users where username = ?");
- $statement->bind_param("s", $username);
- $statement->execute();
- }
- // AccountsModel.php
- public function login($username, $password){
- $statement = self::$db->prepare("SELECT Id, username, pass_hash FROM Users WHERE Username = ?");
- $statement->bind_param("s", $username);
- $statement->execute();
- $result = $statement->get_result()->fetch_assoc();
- if(password_verify($password, $result['pass_hash'])){
- return true;
- }
- return false;
- }
- //AccountsController.php
- public function login(){
- if($this->isPost){
- $username = $_POST['username'];
- $password = $_POST['password'];
- $isLoggedIn = $this->db->login($username, $password);
- if($isLoggedIn){
- $_SESSION['username'] = $username;
- $this->addInfoMessage("Successfully login.");
- return $this->redirect("home");
- } else {
- $this->addErrorMessage("Login error.");
- }
- }
- $this->renderView(__FUNCTION__);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement