public function with_hashes()
    {
        $oUri    = Factory::service('Uri');
        $oConfig = Factory::service('Config');

        if (!$oConfig->item('authEnableHashedLogin')) {
            show404();
        }

        // --------------------------------------------------------------------------

        $hash['id'] = $oUri->segment(4);
        $hash['pw'] = $oUri->segment(5);

        if (empty($hash['id']) || empty($hash['pw'])) {
            throw new NailsException(lang('auth_with_hashes_incomplete_creds'), 1);
        }

        // --------------------------------------------------------------------------

        /**
         * If the user is already logged in we need to check to see if we check to see if they are
         * attempting to login as themselves, if so we redirect, otherwise we log them out and try
         * again using the hashes.
         */

        if (isLoggedIn()) {

            if (md5(activeUser('id')) == $hash['id']) {

                //  We are attempting to log in as who we're already logged in as, redirect normally
                if ($this->data['return_to']) {

                    redirect($this->data['return_to']);

                } else {

                    //  Nowhere to go? Send them to their default homepage
                    redirect(activeUser('group_homepage'));
                }

            } else {

                //  We are logging in as someone else, log the current user out and try again
                $oAuthModel = Factory::model('Auth', 'nails/module-auth');
                $oAuthModel->logout();

                redirect(preg_replace('/^\//', '', $_SERVER['REQUEST_URI']));
            }
        }

        // --------------------------------------------------------------------------

        /**
         * The active user is a guest, we must look up the hashed user and log them in
         * if all is ok otherwise we report an error.
         */

        $oSession   = Factory::service('Session', 'nails/module-auth');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $oUser      = $oUserModel->getByHashes($hash['id'], $hash['pw']);

        // --------------------------------------------------------------------------

        if ($oUser) {

            //  User was verified, log the user in
            $oUserModel->setLoginData($oUser->id);

            // --------------------------------------------------------------------------

            //  Say hello
            if ($oUser->last_login) {

                $lastLogin = $oConfig->item('authShowNicetimeOnLogin') ? niceTime(strtotime($oUser->last_login)) : toUserDatetime($oUser->last_login);

                if ($oConfig->item('authShowLastIpOnLogin')) {
                    $sStatus  = 'positive';
                    $sMessage = lang('auth_login_ok_welcome_with_ip', [
                        $oUser->first_name,
                        $lastLogin,
                        $oUser->last_ip,
                    ]);
                } else {
                    $sStatus  = 'positive';
                    $sMessage = lang('auth_login_ok_welcome', [$oUser->first_name, $oUser->last_login]);
                }

            } else {
                $sStatus  = 'positive';
                $sMessage = lang('auth_login_ok_welcome_notime', [$oUser->first_name]);
            }

            $oSession->setFlashData($sStatus, $sMessage);

            // --------------------------------------------------------------------------

            //  Update their last login
            $oUserModel->updateLastLogin($oUser->id);

            // --------------------------------------------------------------------------

            //  Redirect user
            if ($this->data['return_to'] != site_url()) {

                //  We have somewhere we want to go
                redirect($this->data['return_to']);

            } else {

                //  Nowhere to go? Send them to their default homepage
                redirect($oUser->group_homepage);
            }

        } else {

            //  Bad lookup, invalid hash.
            $oSession->setFlashData('error', lang('auth_with_hashes_autologin_fail'));
            redirect($this->data['return_to']);
        }
    }