Could you elaborate on 'my script fails': how does it fail? Does it generate an error? Falsely claim the password is incorrect?

That said, it seems likely that the special characters have special meanings to the shell - single quotes for example, and the qx($cmd) call is failing on that. For example, if the content of the $cmd variable is:

ldapsearch -h 127.0.0.1 -b 'dc=xyz, dc=com' -D 'cn=user,dc=xyz,dc=com' + -w xy'z employeenumber dn

the shell will grumble over the unmatched ' in the middle of the password.

You would probably find this much easier to write and maintain using Net::LDAP, and you could do away with the relatively inefficient "bind and search" done from the command line, in favour of a simple "bind". Also, using Net::LDAP would reduce the possibility of an injection attack passing malicious code to the command line.

Update: Slightly OT, I notice that you're doing the same ldapsearch 2ce, 1ce as anonymous to get the userdn, then again as the user to validate the password. That's pretty inefficient, especially if employeenumber isn't indexed. You would probably get a significant speed improvement by using  -b $userdn -s base in the second search.

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."

John Brunner, "The Shockwave Rider".


In reply to Re: LDAP Authentication by g0n
in thread LDAP Authentication by bar10der

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.