adldap / adLDAP

adLDAP is a PHP class that provides LDAP authentication and integration with Active Directory.
GNU Lesser General Public License v2.1
423 stars 204 forks source link

Password change failes on multibyte strings #38

Open ringej opened 10 years ago

ringej commented 10 years ago

The encodePassword() functions failes on multibyte strings like utf-8 passwords with german umlauts (ä,ö,ü,ß, etc.) because the functions just adds zerobytes after every character which ends up in invalid utf-16le.

I replaced the original function:

public function encodePassword($password) { $password="\"".$password."\""; $encoded=""; for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; } return $encoded; }

with this:

public function encodePassword($password) { $encoded = mb_convert_encoding('"' . $password . '"', 'utf-16le', 'utf-8'); return $encoded; }

this worked for me.

have a nice day, johannes

ralfbecker commented 10 years ago

Have a look at my pull request: https://github.com/adldap/adLDAP/pull/5

It implements utf-8 handling, if mbstring externsion is available, and falls back to current code, if not.

Ralf

ringej commented 10 years ago

Great, thanks. I looked at your encodePassword function and it's amlost the same as mine, but ... You use mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset); Correct me if I'm wrong, but it $charset is set to iso-8859-1 and the password comes in utf-8 from a POST request, wouldn't it fail, too?

Johannes

ralfbecker commented 10 years ago

Hi Johannes,

default is still "iso-8859-1", to behave like stock adLDAP.

If you want to use a different internal encoding, you have to set it via adLDAP constructor attribute "charset", eg.: $ad = new adLDAP(array( 'charset' => 'utf-8', // other options ... ));

Ralf