Example #1
0
 function Login($id, $username, $password)
 {
     $active = false;
     $user = new User();
     $user->SetDatabase($this->database);
     $user->SetUsername($username);
     $user->SetPassword($password);
     if ($id == "") {
         $user->Encrypt($password);
     } else {
         $user->SetEncryptedPassword($password);
     }
     $this->logged_in = false;
     if ($user->UserExists()) {
         if ($user->CheckPassword()) {
             $this->logged_in = true;
             $user->SelectByName();
         }
     }
     if ($this->logged_in) {
         if ($user->GetUsername() == "guest") {
             $this->logged_in = false;
         }
         if ($id != "") {
             $this->SetId($id);
             $this->SelectById();
             $this->SetUser($user->GetId());
             if ($this->Update()) {
                 $this->UnsetCookie();
                 $this->SetCookie($user->GetUsername());
             }
             if ($this->GetActive()) {
                 $active = true;
             }
         }
         if (!$active) {
             $this->SetDateStart(date('Y-m-d H:i:s'));
             $this->SetDateLast(date('Y-m-d H:i:s'));
             $this->SetActive(1);
             $this->SetIp($_SERVER['REMOTE_ADDR']);
             $this->SetUser($user->GetId());
             if ($this->Insert()) {
                 $this->UnsetCookie();
                 $this->SetCookie($user->GetUsername());
                 return $this->id;
             }
         } else {
             $this->SetDateLast(date('Y-m-d H:i:s', time()));
             $this->Update();
             return $this->id;
         }
     }
     $this->logged_in = false;
     return false;
 }