Q:

How to restrict access to the site during development?

I am creating a new Drupal 7 based site. 
The development will be on a server that is publicly accessible. I am working in a multi-site environment. 
I would like to totally block access to the site to anyone & anything but authorized users. Including access to the site name, theme, etc... 
I used Secure Site for similar tasks before. It did http-level authentication and returned 403 when authentication failed. It doesn't have a D7 version. 
What would be the easiest way to do this? 

A:

Make a module and paste following code in your module file:
<?php

/**
 * Implementation of hook_boot().
 *
 * Ask for user credentials and try to authenticate.
 */
function foo_boot() {
  require_once DRUPAL_ROOT . '/includes/password.inc';

  if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
    $query = "SELECT pass FROM {users} WHERE name = :name";
    $result = db_query($query, array(':name' => $_SERVER['PHP_AUTH_USER']));
    $account = new stdClass();
    foreach ($result as $row) {
      $account->pass = $row->pass;
    }
    if (isset($account->pass)) {
      if (user_check_password($_SERVER['PHP_AUTH_PW'], $account)) {
        return;
      }
    }
  }

  header('WWW-Authenticate: Basic realm="Development"');
  header('HTTP/1.0 401 Unauthorized');
  exit;
}

This uses HTTP Authentication and checks the Drupal Database for a valid username and password.
If you have any problems with PHP CLI, Drush or cron, you can add following code in the hook:
  // Allow cron through
  if (basename($_SERVER['PHP_SELF']) == 'cron.php') {
    return;
  }  

  // Allow PHP CLI/Drush through
  if (isset($_SERVER['argc'])) {
    if (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)) {
      return;
    }
  }

A:

If you're using Drupal 7 the Shield module is available for this purpose.  It authenticates a single, shared user and password.

PHP Authentication shield. It creates a simple shield for the site with Apache authentication. It hides the sites, if the user does not know a simple username/password. It handles Drupal as a "walled garden".
  This module helps you to protect your (dev) site with HTTP authentication.

