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;
 }
 function GetUserId()
 {
     $user = new User();
     $user->SetDatabase($this->database);
     $user->SetUsername($this->username);
     $user->SetPassword($this->password);
     $user->Encrypt();
     if ($user->SelectByName()) {
         return $user->GetId();
     } else {
         return 0;
     }
 }
Example #3
0
<?php

/*
 * doLogin.php
 *
 * The login action.
 *
 * Written by: Bruno Schifer Bernardi
 * Last Updated: August 01, 2007
 */
require '../../schifers/constants/cdConstants.php';
require '../../' . $WEB_SITE . 'src/cdDatabase.php';
require '../../' . $WEB_SITE . 'src/cdUser.php';
require '../../' . $WEB_SITE . 'src/cdSession.php';
$username = $_POST["p_username"];
$password = $_POST["p_password"];
$id = $_POST["p_session_id"];
$user = new User();
$user->SetDatabase($database);
$user->SetUsername($username);
$user->SetPassword($password);
$user->Encrypt();
$session = new Session();
$session->SetDatabase($database);
$session->SetUser($user);
$session->Login($id, $username, $user->GetEncryptedPassword());
if ($session->IsLoggedIn()) {
    echo "<script language='Javascript'> window.location = \"/" . $WEB_SITE . "pages/pgRestricted.php\" </script>";
} else {
    echo "<script language='Javascript'> window.location = \"/index.php?error_message=Login Inválido!\" </script>";
}