PHP Code:
$auth false;
$authuser $_SERVER['php_auth_user'];
$authpass $_SERVER['php_auth_pw'];
if (isset(
$authuser) && isset($authpass))
{
    
$result mysql_query('SELECT name,passhash FROM users WHERE id=1');
    if (!
$result)
    {
        echo 
'Failed to determine root user\\'s name.';
        exit;
    }
    else
    {
        $s = mysql_fetch_row($result);
        $name = $s[0];
        $passhash = $s[1];
        if ($authuser == $name && md5($authpass) == $passhash)
        {
            $auth = true;
        }
    }
}
if (!$auth)
{
    header("WWW-Authenticate: Basic realm=\"Garnet Server Login\"");
    header('
HTTP/1.0 401 Unauthorized');
    echo '
Login failed.';
    exit;

I tested the query and it works fine (i.e., returns the name and password hash). But the authentication dialog that pops up never accepts the username and password.