#!/usr/local/bin/perl

use HTTPD::Authen ();
use Getopt::Std;
use File::Basename;

getopts('ht:s:e:f:');

$db = $dbtype = $server = undef;
$dlm = '\s+'; 

usage($opt_h) if defined $opt_h;
$db = $opt_f || ".htpasswd";
$dbtype = $opt_t if defined $opt_t;
$server = $opt_s if defined $opt_s;
#$enc    = $opt_e if defined $opt_e;

$authen = new HTTPD::Authen
    DB     => $db,
    DBType => $dbtype,
    Server => $server;

$valid = $authen->basic->check(@ARGV);

print $valid ? "ok\n" : "not ok\n";

sub usage {
    my $script = basename $0;
    print <<"USAGE";
usage:
$script [options] <username> <password> 
options:
-f <db>     where db is the database file
-t <dbtype> where dbtype is one of 'Text', 'DBM' or 'SQL', default is 'DBM'
-s <server> where server is the HTTP server name e.g. 'cern'
            default works with ncsa, apache, netscape and possibly others.
USAGE

}
