Apache-AuthenMT

 view release on metacpan or  search on metacpan

AuthenMT.pm  view on Meta::CPAN

    my($res, $sent_pw) = $r->get_basic_auth_pw;
    return $res if $res != OK;
    my $user = $r->connection->user;
    
    # start up Movable Type
    my $app = MT::App->new( 
        Config    => $MT_DIR . 'mt.cfg',
        Directory => $MT_DIR 
    ) or $reason = MT::App::->errstr;

    # check password
    $reason = authenticate($r, $user, $sent_pw) unless ($reason);

    # reason for failure
    if ($reason) {
       #$r->note_basic_auth_failure;
       #$r->log_reason($reason, $r->filename);
       return AUTH_REQUIRED;
    }

    # authenticated
    return OK;
}

# check user and password against Movable Type's database
sub authenticate {
    my $r       = shift;
    my $user    = shift;
    my $sent_pw = shift;
    my $crypted = 0;
    # print STDERR "authmt: $user $sent_pw\n";

    if (my $author = MT::Author->load({ name => $user })) {
        if ($author->is_valid_password($sent_pw, $crypted)) {
            return "";
        } else {
            return "invalid pass";
        }
    } else {
        return "invalid user";
    }
}

=head1 NAME

AuthenMT.pm  view on Meta::CPAN

=head1 METHODS

=over 4

=item handler

mod_perl auth handler

=item authenticate

This checks the user and password against database.

=back

=head1 VARIABLES

=over 4

=item MT_DIR

This variable should contain the path to your Movable Type perl modules.



( run in 0.954 second using v1.01-cache-2.11-cpan-49f99fa48dc )