Open ringej opened 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
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
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
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