comparison lib/CPT/Auth.pm @ 1:f093e08f21f3 draft default tip

planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author cpt
date Mon, 05 Jun 2023 02:47:24 +0000
parents
children
comparison
equal deleted inserted replaced
0:b8b8b52904a5 1:f093e08f21f3
1 package CPT::Auth;
2 use strict;
3 use warnings;
4 use autodie;
5 use Moose;
6
7 has DN => (
8 is => 'rw',
9 isa => 'Str',
10 );
11
12
13 sub check_credentials {
14 my ( $self, %params ) = @_;
15 use Net::LDAPS;
16 print STDERR "Connecting to LDAP\n";
17 my $base = 'dc=tamu,dc=edu';
18 my $ldap = Net::LDAPS->new('00-ldap-biobio.tamu.edu') or die "$@";
19 my $mesg = $ldap->bind; # an anonymous bind
20
21 my $username = $params{'username'};
22 my $password = $params{'password'};
23
24 $mesg = $ldap->search( # perform a search
25 base => $base,
26 filter => "uid=$username",
27 );
28 my $max = $mesg->count;
29
30 # Should we exit early?
31 for ( my $i = 0 ; $i < $max ; $i++ ) {
32 my $entry = $mesg->entry($i);
33 $self->DN() = $entry->dn();
34 }
35 $mesg = $ldap->bind( $self->DN(), password => $password );
36 if ( $mesg->error() eq 'Success' ) {
37 return 1;
38
39 #print "Succesfully logged you in";
40 }
41 else {
42 return 0;
43
44 #print "Error: ";
45 #print $mesg->error();
46 }
47 }
48
49 no Moose;
50 1;
51
52 __END__
53
54 =pod
55
56 =encoding UTF-8
57
58 =head1 NAME
59
60 CPT::Auth
61
62 =head1 VERSION
63
64 version 1.99.4
65
66 =head2 check_credentials
67
68 $cptauth->check_credentials(username=>'J.doe',password=>$password);
69
70 return 1 or 0, based on success or failure, respectively.
71
72 =head1 AUTHOR
73
74 Eric Rasche <rasche.eric@yandex.ru>
75
76 =head1 COPYRIGHT AND LICENSE
77
78 This software is Copyright (c) 2014 by Eric Rasche.
79
80 This is free software, licensed under:
81
82 The GNU General Public License, Version 3, June 2007
83
84 =cut