Ignoring issues with maintaing state, getting the username and password from <insert data source here>, etc etc...
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...
}
}
That should at least help you get started. It searches for the user, and if found, attempts to bind as the user (with the user's password). If it can successfully bind, you know the password supplied is correct and you can go ahead and set a cookie or whatnot.
Note that the above code is also untested, and should only be used as something to get you started thinking about the process you'll want to implement.
-s.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.