Code Comments
Programming Forum and web based access to our favorite programming groups.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;
Post Follow-up to this messageHi,
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
Post Follow-up to this messagele 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 i n > the Latin1 (aka ISO-8859-1) character set. I may be mistaken, but I think it works for every encoding. thanks and regards mc
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.