Thursday, April 28, 2011

Adding \000 to each char in a password string

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.

From stackoverflow
  • 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).

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

0 comments:

Post a Comment