src/Common/Controller/Base.php
protected function passwordProtected()
    {
        /**
         * To password protect an environment you must create a constant which is
         * a JSON string of key/value pairs (where the key is the username and the
         * value is a sha1 hash of the password):
         *
         *     {
         *         'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
         *         'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'
         *     }
         *
         * You may also whitelist IP/IP Ranges by providing an array of IP Ranges
         *
         *      [
         *          '123.456.789.123',
         *          '123.456/789'
         *      ]
         */

        $oInput                 = Factory::service('Input');
        $sConstantName          = 'APP_USER_PASS_' . Environment::get();
        $sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment::get();

        if (!$oInput::isCli() && defined($sConstantName)) {

            //  On the whitelist?
            if (defined($sConstantNameWhitelist)) {

                $oInput          = Factory::service('Input');
                $aWhitelsitedIps = @json_decode(constant($sConstantNameWhitelist));
                $bWhitelisted    = isIpInRange($oInput->ipAddress(), $aWhitelsitedIps);

            } else {

                $bWhitelisted = false;
            }

            if (!$bWhitelisted) {

                $oCredentials = @json_decode(constant($sConstantName));

                if (empty($_SERVER['PHP_AUTH_USER'])) {
                    $this->passwordProtectedRequest();
                }

                if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {

                    //  Determine the users
                    $bIsSet   = isset($oCredentials->{$_SERVER['PHP_AUTH_USER']});
                    $bIsEqual = $bIsSet && $oCredentials->{$_SERVER['PHP_AUTH_USER']} == hash('sha256', $_SERVER['PHP_AUTH_PW']);
                    if (!$bIsSet || !$bIsEqual) {
                        $this->passwordProtectedRequest();
                    }

                } else {

                    $this->passwordProtectedRequest();
                }
            }
        }
    }
protected function passwordProtected()
    {
        /**
         * To password protect an environment you must create a constant which is
         * a JSON string of key/value pairs (where the key is the username and the
         * value is a sha1 hash of the password):
         *
         *     {
         *         'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
         *         'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'
         *     }
         *
         * You may also whitelist IP/IP Ranges by providing an array of IP Ranges
         *
         *      [
         *          '123.456.789.123',
         *          '123.456/789'
         *      ]
         */

        $oInput                 = Factory::service('Input');
        $sConstantName          = 'APP_USER_PASS_' . Environment::get();
        $sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment::get();

        if (!$oInput::isCli() && defined($sConstantName)) {

            //  On the whitelist?
            if (defined($sConstantNameWhitelist)) {

                $oInput          = Factory::service('Input');
                $aWhitelsitedIps = @json_decode(constant($sConstantNameWhitelist));
                $bWhitelisted    = isIpInRange($oInput->ipAddress(), $aWhitelsitedIps);

            } else {

                $bWhitelisted = false;
            }

            if (!$bWhitelisted) {

                $oCredentials = @json_decode(constant($sConstantName));

                if (empty($_SERVER['PHP_AUTH_USER'])) {
                    $this->passwordProtectedRequest();
                }

                if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {

                    //  Determine the users
                    $bIsSet   = isset($oCredentials->{$_SERVER['PHP_AUTH_USER']});
                    $bIsEqual = $bIsSet && $oCredentials->{$_SERVER['PHP_AUTH_USER']} == hash('sha256', $_SERVER['PHP_AUTH_PW']);
                    if (!$bIsSet || !$bIsEqual) {
                        $this->passwordProtectedRequest();
                    }

                } else {

                    $this->passwordProtectedRequest();
                }
            }
        }
    }
protected function passwordProtected ( ) { /**
         * To password protect an environment you must create a constant which is
         * a JSON string of key/value pairs (where the key is the username and the
         * value is a sha1 hash of the password):
         *
         *     {
         *         'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
         *         'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'
         *     }
         *
         * You may also whitelist IP/IP Ranges by providing an array of IP Ranges
         *
         *      [
         *          '123.456.789.123',
         *          '123.456/789'
         *      ]
         */ $ oInput = Factory :: service ( 'Input' ) ; $ sConstantName = 'APP_USER_PASS_' . Environment :: get ( ) ; $ sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment :: get ( ) ; if ( ! $ oInput :: isCli ( ) && defined ( $ sConstantName ) ) { //  On the whitelist? if ( defined ( $ sConstantNameWhitelist ) ) { $ oInput = Factory :: service ( 'Input' ) ; $ aWhitelsitedIps = @ json_decode ( constant ( $ sConstantNameWhitelist ) ) ; $ bWhitelisted = isIpInRange ( $ oInput -> ipAddress ( ) , $ aWhitelsitedIps ) ; } else { $ bWhitelisted = false ; } if ( ! $ bWhitelisted ) { $ oCredentials = @ json_decode ( constant ( $ sConstantName ) ) ; if ( empty ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ) { $ this -> passwordProtectedRequest ( ) ; } if ( isset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) && isset ( $ _SERVER [ 'PHP_AUTH_PW' ] ) ) { //  Determine the users $ bIsSet = isset ( $ oCredentials -> { $ _SERVER [ 'PHP_AUTH_USER' ] } ) ; $ bIsEqual = $ bIsSet && $ oCredentials -> { $ _SERVER [ 'PHP_AUTH_USER' ] } == hash ( 'sha256' , $ _SERVER [ 'PHP_AUTH_PW' ] ) ; if ( ! $ bIsSet || ! $ bIsEqual ) { $ this -> passwordProtectedRequest ( ) ; } } else { $ this -> passwordProtectedRequest ( ) ; } } } }
Checks if credentials should be requested for staging environments

@return void
Checks if credentials should be requested for staging environments