/ Published in: PHP
Expand |
Embed | Plain Text
class Auth { var $user_id; var $username; var $password; var $ok; var $salt = "34asdf34"; var $domain = ".domain.com"; function Auth() { global $db; $this->user_id = 0; $this->username = "Guest"; $this->ok = false; if(!$this->check_session()) $this->check_cookie(); return $this->ok; } function check_session() { return $this->check($_SESSION['auth_username'], $_SESSION['auth_password']); else return false; } function check_cookie() { return $this->check($_COOKIE['auth_username'], $_COOKIE['auth_password']); else return false; } function login($username, $password) { global $db; $db->query("SELECT user_id FROM users WHERE username = '$username' AND password = '$password'"); { $this->username = $username; $this->ok = true; $_SESSION['auth_username'] = $username; return true; } return false; } function check($username, $password) { global $db; $db->query("SELECT user_id, password FROM users WHERE username = '$username'"); { { $this->username = $username; $this->ok = true; return true; } } return false; } function logout() { $this->user_id = 0; $this->username = "Guest"; $this->ok = false; $_SESSION['auth_username'] = ""; $_SESSION['auth_password'] = ""; } }
Comments
Subscribe to comments
You need to login to post a comment.

you shouldn't store username/password in a cookie mate