1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ldap password modification with php

Discussion in 'PHP' started by nathan_nz, Nov 19, 2007.

  1. #1
    Hi all..
    I am facing problem in password changing of user.
    The user has to pass the old password and new paswd.
    Since I have enabled the pwdSafeModify in LDAP, my LDAP wil not allow to change without the old password.
    But php ldap_mod_replace and modify functions specify only new passwords.
    So anybody please tell me how can I pass both old and new passwords to LDAP..
    Thanks in advance
     
    nathan_nz, Nov 19, 2007 IP
  2. adient

    adient Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I was also unable to find any implementation in PHP of the PASSMOD action described in RFC 3062. A standard mod_replace attempt fails, requesting that the user also supply the old password.

    Although PHP also has the Net::LDAP library through PEAR, I was unable to find the 'SetPassword' extension provided by the Net::LDAP library in perl.

    Thus, a simple perl script was pasted together:

    
    #!/usr/bin/perl
    # Requires: perl-ldap, perl-IO-Socket-SSL
    
    use Net::LDAP;
    use Net::LDAP::Extension::SetPassword;
    
    
    $host = shift;
    $dn = shift;
    $pw_old = shift;
    $pw_new = shift;
    
    
    $ldap = Net::LDAP->new($host);
    
    $result = $ldap->start_tls();
    
    die "Error: ".$result->error()."\n" if $result->code();
    
    $ldap->bind( $dn, password => $pw_old );
    
    $result = $ldap->set_password( oldpasswd => $pw_old, newpasswd => $pw_new );
    
    print $result->error();
    
    Code (markup):
    Call this from PHP using exec():

    
    $host = 'your ldap host';
    $dn = 'full dn of user changing pass';
    $result = exec("passmod.pl $host $dn $pw_old $pw_new");
    
    Code (markup):
    If anyone has a true PHP implementation of this, please let me know.
     
    adient, Nov 5, 2009 IP
  3. AlphaBillion

    AlphaBillion Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanx for that. Very good
     
    AlphaBillion, Nov 5, 2009 IP