public function login() { // If already authenticated redirect redirect_if_authenticated('You are already logged in.'); $viewdata = array(); if ($_POST) { // Post request $this->load->model('user/LoginInput'); if ($this->LoginInput->is_valid()) { // Success // Try to get the user by email $this->load->model('user/UserModel'); $user = $this->UserModel->get_by_email($this->LoginInput->get_email()); // Check if user was found if ($user != NULL) { // Verify credentials $this->load->helper('crypto'); $isvalidcredentials = verify_hash($user->passwordhash, $this->LoginInput->get_password(), $user->passwordsalt); if ($isvalidcredentials) { // Success // Login $authUser = new AuthenticatedUser($user->id, $user->email, $user->firstname, $user->lastname, $user->isadmin, $user->hasimage); $this->authenticationservice->login($authUser); // Set status message set_status_message('You have been logged in!'); // Redirct - returns immediatly return redirect(profile_route()); } } // Set status message set_status_message('Login was incorrect. Please try again.', $viewdata); } } // Default fallback $this->template->load('user/login', $viewdata); }
public static function authenticate($username, $password) { $user = User::getByUsername($username); if (!$user || !verify_hash($password, $user->password)) { return false; } $user->setAuthenticated(); return true; }
return $password; } } function verify_hash($password, $hash, $salt) { $md5 = md5($salt . $password); return $md5 == $hash; } $protocol = $_SERVER["HTTP_AUTH_PROTOCOL"]; if ($_SERVER["HTTP_AUTH_METHOD"] == "apop") { $username = $_SERVER["HTTP_AUTH_USER"]; $userpass = get_password($username); if ($userpass) { $hash = $_SERVER["HTTP_AUTH_PASS"]; $salt = $_SERVER["HTTP_AUTH_SALT"]; if (verify_hash($userpass, $hash, $salt)) { get_mailserver($DBMAIL, $protocol); header("Auth-Pass: {$userpass}"); } else { fail(); } } else { fail(); } } else { get_mailserver($DBMAIL, $protocol); } function get_mailserver($config, $protocol) { // default backend port $port = $config['POP3'];