Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Imos::AuthCookieHandler;
- use strict;
- use diagnostics;
- use Apache2::Const qw(:common HTTP_FORBIDDEN);
- use Apache2::AuthCookie;
- use Apache2::RequestRec;
- use Apache2::RequestIO;
- use vars qw($VERSION @ISA);
- use Digest::MD5 qw(md5 md5_hex);
- use DBI;
- $VERSION = substr(q$Revision: 220 $, 10);
- @ISA = qw(Apache2::AuthCookie);
- sub authen_cred ($$\@) {
- my $self = shift;
- my $r = shift;
- my @creds = @_;
- my $dbh = DBI->connect("dbi:SQLite:dbname=" . $r->dir_config->get('DatabasePath'), "", "");
- unless ($dbh) {
- $r->server->log_error("Database connection failed: " . $DBI::errstr);
- $r->print("Es ist ein unerwarteter Fehler aufgetreten");
- return 0;
- }
- my $q = "SELECT user_id, login, password FROM users WHERE login = ? AND password = ?";
- my $sth = $dbh->prepare($q);
- unless ($sth) {
- $r->server->log_error("Preparing failed for query=(" . $q . "): " . $DBI::errstr);
- $r->print("Es ist ein unerwarteter Fehler aufgetreten");
- return 0;
- }
- # Generate password hash
- my $md5 = Digest::MD5->new;
- $md5->add($creds[1]);
- $sth->execute($creds[0], $md5->hexdigest);
- my @r = $sth->fetchrow_array;
- # Found database entry?
- return unless @r;
- # We got a entry
- join(":", @r);
- }
- sub authen_ses_key ($$$) {
- my ($self, $r, $cookie) = @_;
- my @parts = split(/:/, $cookie);
- $r->server->log_error(@parts);
- $r->server->log_error("user=" . $parts[1] . " cookie=$cookie");
- if ($parts[0] eq 1) {
- return $parts[0];
- } else {
- return;
- }
- }
- 1;
Add Comment
Please, Sign In to add comment