Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login($username, $password){
- $this->db->query("SELECT * FROM users WHERE username = :username AND status = :status LIMIT 1");
- $this->db->bind(':username', $username);
- $this->db->bind(':status', 1);
- $row = $this->db->single();
- $count = $this->db->rowCount();
- if ($count > 0) {
- if (password_verify($password, $row['password'])) {
- $_SESSION['session'] = [
- 'id' => $row['id'],
- 'username' => $row['username'],
- 'email' => $row['email'],
- ];
- return true;
- } else {
- return false;
- }
- }
- }
- public function isLoggedIn() {
- if (isset($_SESSION['session'])) {
- return true;
- }
- }
- if ($user->isLoggedIn()) {
- header('Location: index.php');
- exit();
- }
- if(isset($_POST['login'])){
- //Retrieve the field values from our login form.
- $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
- $password = !empty($_POST['password']) ? trim($_POST['password']) : null;
- if($user->login($username, $password)) {
- header('Location: index.php');
- exit();
- } else {
- $message[] = 'We found problems with the login, please try again.';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement