NG auth: internal db auth, RT#21563
[freeside.git] / FS / FS / Auth / internal.pm
1 package FS::Auth::internal;
2 #use base qw( FS::Auth );
3
4 use strict;
5 use Crypt::Eksblowfish::Bcrypt qw(bcrypt_hash);
6 use FS::Record qw( qsearchs );
7 use FS::access_user;
8
9 sub authenticate {
10   my($self, $username, $check_password ) = @_;
11
12   my $access_user = qsearchs('access_user', { 'username' => $username,
13                                               'disabled' => '',
14                                             }
15                             )
16     or return 0;
17
18   if ( $access_user->_password_encoding eq 'bcrypt' ) {
19
20     my( $cost, $salt, $hash ) = split(',', $access_user->_password);
21
22     my $check_hash = bcrypt_hash( { key_nul => 1,
23                                     cost    => $cost,
24                                     salt    => $salt,
25                                   },
26                                   $check_password
27                                 );
28
29     $hash eq $check_hash;
30
31   } else { 
32
33     return 0 if $access_user->_password eq 'notyet'
34              || $access_user->_password eq '';
35
36     $access_user->_password eq $check_password;
37
38   }
39
40 }
41
42 #sub change_password {
43 #}
44
45 1;