/** * logges in a user by his username * @param string $username * @param string $password * @return boolean */ public function login($username, $password) { // query for the password $query = DB::getInstance()->db()->prepare("SELECT id, password FROM users WHERE username=:username LIMIT 1"); $query->execute(['username' => $username]); // fetch data if the user exists if ($query->rowCount()) { $data = $query->fetch(); if (Hash::verifyPassword($password, $data['password'])) { // set the session Session::set($this->session_name, $data['id']); return true; } else { $this->auth_error_message = 'You have entered the wrong password!'; return false; } } else { $this->auth_error_message = 'Invalid login credentials!'; return false; } }
/** * deletes an articles from the database * @param integer $id */ public function delete($id) { $query = DB::getInstance()->db()->prepare("DELETE FROM articles WHERE id=:id"); $query->execute(['id' => $id]); }