The localauth routine receives four arguments (in the order: two required, one optrional, another required).
A common use of localauth.pm is to connect with an LDAP service.
package localauth;use strict;
use Net::LDAP;
use Net::LDAPS;
sub localauth {
my ($username,$password) = @_;}my $ldap_host_name = ''; # insert the host name of your ldap server, e.g., ldap.msu.edu
my $ldap_ca_file_name = ''; # insert the ldap certificate filename - include absolute path
# certificate is required if you wish to encrypt the password.
# e.g., /home/http/perl/lib/local/ldap.certificate
my $ldap_search_base = ''; # ldap search base, this might be set to 'o=msu.edu'.
my $ldap = Net::LDAPS->new(
$ldap_host_name,);verify => 'require', # 'require' -> a certificate is needed, -> 'none' if no certificate used
cafile => $ldap_ca_file_name,
if (!(defined($ldap))) {
return (0);}$ldap->bind;
my $search_string = '(uid=".$username.")';
my $mesg = $ldap->search (
base => $ldap_search_base,);filter => $search_string,
attrs => ['dn'] ,
if ($mesg->code) {
$ldap->unbind;}$ldap->disconnect;
return (0);
my @entries = $mesg->all_entries;
if (@entries > 0) {
$ldap->unbind;}$ldap->disconnect;
return (0);
$mesg = $ldap->bind (
dn => $entries[0]->dn,);password => $password,
$ldap->unbind;
$ldap->disconnect;
if ($mesg->code) {
return (0)}return (1);
1;