use Net::LDAP; # Information you'll need to populate somehow (form?) my $base = 'dc=domain,dc=com'; my $user = 'testuser'; my $pass = 'p4ssw0rd'; my $ldap = Net::LDAP->new($host}); my $mesg = $ldap->search( base => $base, filter => "uid=$user" ); my ($dn); # Search for the user's DN within the base/filter my $max = $mesg->count; for (my $i = 0; $i < $max; $i++) { my $entry = $mesg->entry($i); $dn = $entry->dn; }; if ($dn) { # Bind with the DN & password if the user acct exists $mesg = $ldap->bind ($dn, password => $pass); unless ($mesg->code) { # Set the cookie here... } }