views:

54

answers:

1

Why would one do this.

for ($i = 0; $i < $len; $i++) {
    $unicodepassword .= "{$passwd{$i}}\000";
}

Context: This is a password set when creating or modifying a user in Active directory. We are rewriting some ancient code and nothing works without this. Making changes in our LDAP does not require this kind of "encoding".

Also the result of this exercise is called "unicodepassword", seems strange to me.

+2  A: 

Also the result of this exercise is called "unicodepassword", seems strange to me.

This is actually a simple conversion from ASCII to UTF-16 (little endian). For characters > #127, it will translate into a unicode code point whose value is the same as ord($passwd{$i}) (so it will depend on the encoding of the original password).

Artefacto
It might explain why this has worked through our transition from ISO to UTF8. Non ASCII characters were never allowed.
leChuck