develooper Front page | perl.ldap | Postings from May 2008

Need help on Authenticating users.

Thread Next
From:
Srinivas N
Date:
May 4, 2008 03:37
Subject:
Need help on Authenticating users.
Hi,

I have been working with LDAP server configurations from some time and  
now I want to integrate the LDAP in my project.

I want to use LDAP to authenticate the users when they login to my portal.

I found Net::LDAP  as a good perl module that can be used to serve my purpose.

I was successful in executing search statements and here is the code


#! /usr/bin/perl

  use Net::LDAP;

$ldap = Net::LDAP->new ( "<ip address>" ) or die "Connection Failed $@";

$mesg = $ldap->bind ( "<user name>",
                        password => "<password>",
                        version => 3 );


$base = "dc=example,dc=com";

$mesg = $ldap->search (  # perform a search
                         base   => $base,
                         filter => "(objectclass=*)"
                        );

  $mesg->code && die $mesg->error;


foreach $entry ($mesg->all_entries) { $entry->dump; }


for the above code I got the following correct output:


------------------------------------------------------------------------
dn:dc=example,dc=com

dc: example
description: Root LDAP entry for example.com
objectClass: dcObject
              organizationalUnit
              ou: rootobject
------------------------------------------------------------------------

dn:ou=People,dc=example,dc=com

          ou: People
description: All people in organisation
objectClass: organizationalUnit
------------------------------------------------------------------------
dn:uid=srinivas,ou=People,dc=example,dc=com

              uid: srinivas
               cn: srinivas
      objectClass: account
                   posixAccount
                   top
                   shadowAccount
     userPassword: {crypt}$1$zYwJ/asE$DsYRb6CXjzJihNyTV2lC9.
shadowLastChange: 13986
        shadowMax: 99999
    shadowWarning: 7
       loginShell: /bin/bash
        uidNumber: 503
        gidNumber: 100
    homeDirectory: /home/srinivas


now when I am trying to execute compare function whose code is



$mesg = $ldap->compare( $base,
                           attr  => "uid",
                           value => "srinivas"
                         );

$mesg->code && die $mesg->error;

foreach $entry ($mesg->all_entries) { $entry->dump; }

I am getting following error when I execute the above script


No such attribute at ldap_compare.pl line 34, <DATA> line 259.


Can any one suggest whether there are any additional attributed that  
are to be added or any other why that I can compare my username and  
password for authentication.

Can you tell me how to authenticate users with this module with  
username and password from a CGI page.

Any suggestion will be helpful.

Thanks in Advance.
Srinivas.


Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About