Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User
- {
- private $username;
- private $password;
- private $id;
- public __construct() {
- $this->username = "";
- $this->password = "";
- $this->id = 0;
- }
- public function IsValid()
- {
- if($id != 0) return true;
- else return false;
- }
- public function LoadByLogin($username, $password)
- {
- // $sql, populate id if valid
- return $this->IsValid();
- }
- public function LoadByID($id)
- {
- // unMD5 $id, $sql, then set id if valid
- return $this->IsValid();
- }
- }
- class Admin
- {
- private $user;
- private $authenticated;
- public __construct()
- {
- $user = new User();
- $authenticated = "";
- }
- public function IsAuthenticated()
- {
- if($this->authenticated == "") $this->Authenticate();
- return $this->authenticated;
- }
- public function Authenticate()
- {
- if(isset($_SESSION['userid']))
- $this->authenticated = // unhash md5 and pass to $this->user->LoadByID();
- elseif(isset($_POST['username'], $_POST['password'])
- {
- $this->authenticated = $this->user->LoadByLogin($_POST['username'], $_POST['password']);
- if($this->authenticated) $_SESSION['userid'] = md5($user->id);
- }
- else
- $this->authenticated = false;
- }
- }
- $admin = new Admin();
- if($admin->IsAuthenticated())
- {
- Header("Login: admin.php");
- }
- else
- {
- // Login form
- }
Add Comment
Please, Sign In to add comment