For Programmers: Free Programming Magazines  


Home > Archive > LDAP > April 2005 > better code to change a password in AD ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author better code to change a password in AD ?
Marc Chantreux

2005-04-12, 4:02 pm

Hi all,

The sample code that is in the FAQ to update a password in an Active
directory needs modules that are not in the standard perl distribution.
I wrote one exemple which doesn't need those modules. Peraps you can add
it in the FAQ ?

Regards,
mc

package Net::LDAP::AD;
use strict;
use warnings;
use Encode;
use base qw(
Net::LDAP
);


sub passwd {

my ( $ldap , $user , $password );

# $ldap : a Net::LDAPS object
# SSL is *required* by Active Directory to change the password
# $user : DN of the user
# $password : plaintext for the new password

$ldap->modify(
$user , replace => {
unicodePwd => Encode::encode('UTF-16LE',qq("$password") )
}
);

}

package main;


my $msg;

my $ldap = Net::LDAP->new(
'ldaps://your.directory'
) or die "$@";

$msg = $ldap->bind(
'cn=someone who can,dc=your,dc=directory'
, password => 'tryToGuess;-)'
);
die $msg->error if $msg->code;
$ldap->passwd('cn=someone who need a new password,dc=your,dc=directory','Cu@Y4PC!
');
die $msg->error if $msg->code;
Peter Marschall

2005-04-19, 4:05 pm

Hi,

On Tuesday 12 April 2005 18:09, Marc Chantreux wrote:
> The sample code that is in the FAQ to update a password in an Active
> directory needs modules that are not in the standard perl distribution.
> I wrote one exemple which doesn't need those modules. Peraps you can add
> it in the FAQ ?
>
> Regards,
> mc
>
> package Net::LDAP::AD;
> use strict;
> use warnings;
> use Encode;
> use base qw(
> Net::LDAP
> );
>
>
> sub passwd {
>
> my ( $ldap , $user , $password );
>
> # $ldap : a Net::LDAPS object
> # SSL is *required* by Active Directory to change the password
> # $user : DN of the user
> # $password : plaintext for the new password
>
> $ldap->modify(
> $user , replace => {
> unicodePwd => Encode::encode('UTF-16LE',qq("$password") )
> }
> );
>
> }


I may be mistaken, but I think Encode is only available with Perl 5.8.
In addition to that I think that your function only works with passwords in
the Latin1 (aka ISO-8859-1) character set.

The solution in the FAQ works for earlier versions of Perl and and passwords
in other character sets too (provided the Unicode::Map8 character map is
created propely).

Peter
--
Peter Marschall
eMail: peter@adpm.de
Marc Chantreux

2005-04-25, 4:03 pm

le 19/04/2005,
Peter Marschall nous écrivait :
> I may be mistaken, but I think Encode is only available with Perl 5.8.


right !

> In addition to that I think that your function only works with passwords in
> the Latin1 (aka ISO-8859-1) character set.


I may be mistaken, but I think it works for every encoding.

thanks and regards
mc
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com