]> git.imager.perl.org - bse.git/blame - site/cgi-bin/modules/BSE/Passwords.pm
add version numbers to all modules
[bse.git] / site / cgi-bin / modules / BSE / Passwords.pm
CommitLineData
b190a4c1
TC
1package BSE::Passwords;
2use strict;
3
cb7fd78d
TC
4our $VERSION = "1.000";
5
b190a4c1
TC
6# wrapper around using the BSE::Password classes
7
8sub new_password_hash {
9 my ($self, $password) = @_;
10
11 my ($obj, $name) = $self->new_password_handler;
12
13 return ( $obj->hash($password), $name );
14}
15
16sub check_password_hash {
17 my ($self, $hash, $type, $password, $error) = @_;
18
19 my $obj = $self->_load($type);
20 unless ($obj) {
21 $$error = "LOAD";
22 return;
23 }
24
25 unless ($obj->check($hash, $password)) {
26 $$error = "INVALID";
27 return;
28 }
29
30 return 1;
31}
32
33sub new_password_handler {
34 my ($self) = @_;
35
36 my $cfg = BSE::Cfg->single;
37 my @handlers = split /,/, $cfg->entry("basic", "passwords", "cryptSHA256,cryptMD5,crypt,plain");
38
39 for my $handler (@handlers) {
40 my $obj = $self->_load($handler);
41 $obj and return ($obj, $handler);
42 }
43
44 require BSE::Password::Plain;
45 return ( BSE::Password::Plain->new, "plain" );
46}
47
48sub _load {
49 my ($self, $handler) = @_;
50
51 my $class = "BSE::Password::\u$handler";
52 my $file = "BSE/Password/\u$handler.pm";
53
54 eval { require $file; 1 }
55 or return;
56
57 my $obj = $class->new
58 or return;
59
60 return $obj;
61}
62
631;
64