Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('includes/config.php');
- if ($user->is_logged_in()) {
- header('Location: signup.php');
- }
- if (isset($_POST['submit'])) {
- $username = filter_input(INPUT_POST, 'username');
- $password = filter_input(INPUT_POST, 'password');
- if ($user->login($username, $password)) {
- $_SESSION['username'] = $username;
- header('Location: index.php');
- exit;
- } else {
- $error[] = 'Wrong username or password or your account has not been activated.';
- }
- }
- ?>
- private function get_user_hash($username){
- try {
- $stmt = $this->_db->prepare('SELECT password FROM members WHERE username = :username AND active="Yes" ');
- $stmt->execute(array('username' => $username));
- $row = $stmt->fetch();
- return $row['password'];
- } catch(PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';
- }
- }
- public function login($username,$password){
- $hashed = $this->get_user_hash($username);
- if($this->password_verify($password,$hashed) == 1){
- $_SESSION['loggedin'] = true;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement