Log in
Menu

ssha ldap password with php5

While working on openldap integration using php5.3 I noticed that documentation is lacking on how to create a password hash in SSHA that works in the latest PHP versions.  Thought this might help another.

// Generate SSHA hash
mt_srand((double)microtime()*1000000);
$salt = pack("CCCCCCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());
$cpasswd = "{SSHA}" . base64_encode( sha1( $pass . $salt, true) . $salt );

Now just use $cpasswd in the userPassword 

    Benjamin H. Graham - bman

    Benjamin H. Graham - bman

    I like tacos and if you have them, send moar.

    Latest comments