I am uncertain how much simpler you could make Net::LDAP to cope with, with perhaps the exception of the $mesg->code && die $mesg->error dance. I have some existing Net::LDAP code, from a CGI application I am prototyping, which bundles the LDAP access politely away from the main code. I have added more verbose comments to describe it, and it appears thus.

sub authenticate { # instance method, $self is a blessed hash holding various # important details like ldaphost etc. my $self = shift; # $q , a CGI->new query object my $q = shift; # Open an anonymous ldap session (anon reads are allowed) my $ldap = Net::LDAP->new( $ldaphost ) or die "LDAP Connection error" +; $ldap->bind; my $user = $q->param('username'); my $mesg = $ldap->search ( base=>$self->{ldap}{userbase}, filter=>"(&(cn=$user))" ); # one day these dies will be calls to pretty printed # html . mymodule::error->database_error() $mesg->code && die $mesg->error; $ldap->unbind; # Dodgy, I admit : we only expect one account with the uid eq $user my $entry = $mesg->shift_entry; # Bailout if user does not exist in LDAP. return undef unless ($entry); my $ldaphash = $entry->get_value('userPassword'); my $ldapuser = $entry->get_value('uid'); # hash the CGI supplied password to compare with LDAP userPassword my $md5 = Digest::MD5->new; $md5->add( $q->param('phrase') ); my $hash = '{MD5}' . encode_base64($md5->digest, ''); if ( ( $q->param('username') eq $ldapuser) and ($hash eq $ldaphash) ) { my $sessionid = $self->start_session( $q ); return $sessionid; } else { return undef } }

I can see where you're coming from , however rewriting this to use Net::LDAP::Simple , feels more like I'm shuffling the args to different methods rather than simplifying the code. I think search paramaters belong with search methods, not in the constructor.

sub authenticate { my $self = shift; my $q = shift; # Using Net::LDAP::Simple my $ldap = Net::LDAP::Simple->new( host=>$ldaphost , base=>$self->{ldap}{userbase} , searchattrs=>'uid' ) or die "LDAP Connection error"; my $user = $q->param('username'); my $result = $ldap->simplesearch( $user ); die $ldap->error unless $result; $ldap->unbind; my $entry = shift @{$result}; # Bailout if user does not exist in LDAP. return undef unless ($entry); my $ldaphash = $entry->get_value('userPassword'); my $ldapuser = $entry->get_value('uid'); my $md5 = Digest::MD5->new; $md5->add( $q->param('phrase') ); my $hash = '{MD5}' . encode_base64($md5->digest, ''); if ( ( $q->param('username') eq $ldapuser) and ($hash eq $ldaphash) ) { my $sessionid = $self->start_session( $q ); return $sessionid; } else { return undef } }

Please forgive me if I have misunderstood your approach, and for goodness sake keep working on the idea. Collecting peoples ideas RE what would make LDAP simpler to use for them might be a good start. I have considered writing some meta-methods to do commonplace things like move and rename, I reckon your ideas there are spot on. I watch with interest


-toaster

I can't believe it's not psellchecked

In reply to Re: RFC: Net::LDAP::Simple by submersible_toaster
in thread RFC: Net::LDAP::Simple by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.