/** * @param <type> $username * @param <type> $password * @return boolean */ public function login($username, $password) { $user = new User(null, $username, $password); $user = $this->userDao->get($user); if ($user != null) { Session::login($user); setcookie('Bureau_PosicaoApps', '', time() - 3600); //setcookie('Bureau_PosicaoApps', "publicacoes|noticias|videoteca", time() + 3600); setcookie('Bureau_PosicaoApps', $user->getPositions(), time() + 3600); setcookie('Bureau_AppsMinimizados', "0", Config::get('tempo_vida_cookie')); setcookie('logged', '1', time() + 10); return true; } return false; }
/** * Authenticates the given username and password against the database, * Logs the user in and returns a user object on success, otherwise returns false * @param <type> $username * @param <type> $password * @return <type> */ public function authenticate($username, $password) { // Find the user in the db $dao = UserDao::get(); $user = $dao->findByUsername($username); // Perform validation if ($user == NULL || self::getHash($password, $user->Password) !== $user->Password) { return false; } else { // update information, such as login count and last login $dao->updateLoginInfo($user->UserId); $this->_user = $user; // complete the login $this->_login(); return $user; } }
if (!isset($_SESSION)) { session_start(); } if (isset($_SESSION['connected'])) { header("Location: index.php"); exit; } $courrier = "Courriel"; $message = ""; if (isset($_REQUEST['courriel'])) { $courriel = $_REQUEST['courriel']; $motDePasse = $_REQUEST['motDePasse']; require_once '/code/classes/UserDao.php'; require_once '/code/classes/User.php'; $dao = new UserDao(); $u = $dao->get($courriel); if ($u == NULL) { $message = $courriel . ' introuvable'; } else { if ($u->getMotDePasse() != $_REQUEST['motDePasse']) { $message = "Mot de passe érroné"; } else { $_SESSION['connected'] = $u->getNom(); header("Location: admin.php"); exit; } } } ?> <!DOCTYPE html> <html lang="en"><head>