Last active
March 11, 2026 06:29
-
-
Save jatinvaidya/a7b949084a21749b33d7b2ea539caf24 to your computer and use it in GitHub Desktop.
Convert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // INPUT: legacyBase64Hash = the value from the PasswordHash column from your DB | |
| // OUTPUT: Auth0 importable PBKDF2 PHC string | |
| public static convertToAuth0Phc(legacyBase64Hash: string): string { | |
| const buffer = Buffer.from(legacyBase64Hash, 'base64'); | |
| if (buffer.length !== 49 || buffer[0] !== 0x00) { | |
| throw new Error('Invalid hash format.'); | |
| } | |
| const salt = buffer.subarray(1, 17); | |
| const hash = buffer.subarray(17, 49); | |
| const b64Salt = salt.toString('base64').replace(/=+$/, ''); | |
| const b64Hash = hash.toString('base64').replace(/=+$/, ''); | |
| return `$pbkdf2-sha1$i=1000,l=32$${b64Salt}$${b64Hash}`; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"ABf+oMjpucF7nTWm6UZeQA5/eE+575VLInSk7y1Yoeko+m8xdo2/AzySMC2Pd/0XNw==""$pbkdf2-sha1$i=1000,l=32$F/6gyOm5wXudNabpRl5ADg$f3hPue+VSyJ0pO8tWKHpKPpvMXaNvwM8kjAtj3f9Fzc"