File Coverage

blib/lib/Authen/Simple/SSH.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Authen::Simple::SSH;
2              
3 1     1   1056 use strict;
  1         2  
  1         41  
4 1     1   5 use warnings;
  1         2  
  1         38  
5 1     1   15 use base 'Authen::Simple::Adapter';
  1         2  
  1         4247  
6              
7             use Net::SSH::Perl;
8             use Params::Validate qw[];
9              
10             our $VERSION = 0.1;
11              
12             __PACKAGE__->options({
13             host => {
14             type => Params::Validate::SCALAR,
15             default => 'localhost',
16             optional => 1
17             },
18             port => {
19             type => Params::Validate::SCALAR,
20             default => 22,
21             optional => 1
22             },
23             protocol => {
24             type => Params::Validate::SCALAR,
25             default => 2,
26             optional => 1
27             },
28             cipher => {
29             type => Params::Validate::SCALAR,
30             optional => 1
31             }
32             });
33              
34             sub check {
35             my ( $self, $username, $password ) = @_;
36              
37             my $host = $self->host;
38             my %params = (
39             port => $self->port,
40             protocol => $self->protocol,
41             cipher => $self->cipher
42             );
43              
44             my $connection;
45              
46             eval { $connection = Net::SSH::Perl->new( $host, %params ) };
47              
48             if ( my $error = $@ ) {
49              
50             chomp $error;
51              
52             $self->log->error( qq/Failed to connect to '$host'. Reason: '$@'/ )
53             if $self->log;
54              
55             return 0;
56             }
57              
58             eval { $connection->login( $username, $password ) };
59              
60             if ( my $error = $@ ) {
61              
62             chomp $error;
63              
64             $self->log->debug( qq/Failed to authenticate user '$username'. Reason: '$error'/ )
65             if $self->log;
66              
67             return 0;
68             }
69              
70             $self->log->debug( qq/Successfully authenticated user '$username'./ )
71             if $self->log;
72              
73             return 1;
74             }
75              
76             1;
77              
78             __END__