Guest User

Untitled

a guest
Jul 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package Imos::AuthCookieHandler;
  2. use strict;
  3. use diagnostics;
  4. use Apache2::Const qw(:common HTTP_FORBIDDEN);
  5. use Apache2::AuthCookie;
  6. use Apache2::RequestRec;
  7. use Apache2::RequestIO;
  8. use vars qw($VERSION @ISA);
  9.  
  10. use Digest::MD5 qw(md5 md5_hex);
  11.  
  12. use DBI;
  13.  
  14. $VERSION = substr(q$Revision: 220 $, 10);
  15. @ISA = qw(Apache2::AuthCookie);
  16.  
  17. sub authen_cred ($$\@) {
  18. my $self = shift;
  19. my $r = shift;
  20. my @creds = @_;
  21.  
  22. my $dbh = DBI->connect("dbi:SQLite:dbname=" . $r->dir_config->get('DatabasePath'), "", "");
  23. unless ($dbh) {
  24. $r->server->log_error("Database connection failed: " . $DBI::errstr);
  25. $r->print("Es ist ein unerwarteter Fehler aufgetreten");
  26. die;
  27. }
  28.  
  29. my $q = "SELECT user_id, login, password FROM users WHERE login = ? AND password = ?";
  30. my $sth = $dbh->prepare($q);
  31. unless ($sth) {
  32. $r->server->log_error("Preparing failed for query=(" . $q . "): " . $DBI::errstr);
  33. $r->print("Es ist ein unerwarteter Fehler aufgetreten");
  34. die;
  35. }
  36.  
  37. # Generate password hash
  38. my $md5 = Digest::MD5->new;
  39. $md5->add($creds[1]);
  40.  
  41. $sth->execute($creds[0], $md5->hexdigest);
  42. my @r = $sth->fetchrow_array;
  43.  
  44. # Found database entry?
  45. return unless @r;
  46.  
  47.  
  48. # We got a entry
  49. join(":", @r);
  50. }
  51.  
  52. sub authen_ses_key ($$$) {
  53. my ($self, $r, $cookie) = @_;
  54. my $parts = split(/:/, $cookie);
  55.  
  56. $r->server->log_error("user=" . $parts[1] . " cookie=$cookie");
  57.  
  58. if ($parts[0] eq 1) {
  59. return $parts[0];
  60. } else {
  61. return;
  62. }
  63. }
  64.  
  65. 1;
Add Comment
Please, Sign In to add comment