Skip to content

Instantly share code, notes, and snippets.

@JeremySkinner
Created October 10, 2012 08:18
Show Gist options
  • Save JeremySkinner/3863991 to your computer and use it in GitHub Desktop.
Save JeremySkinner/3863991 to your computer and use it in GitHub Desktop.
Replicating .NET Password Hashing in PHP
// From http://gilbert.pellegrom.me/replicating-net-password-hashing-in-php/
/*
* $password is the users password entered at login
* $hashed_password is the password from the database
* $password_salt is the salt from the database
*/
$bytes = mb_convert_encoding($password, 'UTF-16LE');
$salt = base64_decode($password_salt);
$password = base64_encode(sha1($salt . $bytes, true));
if ($password == $hashed_password) return true;
else return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment