Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active July 16, 2019 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/134d8403e512ed70e676175c17bddc27 to your computer and use it in GitHub Desktop.
Save miguelmota/134d8403e512ed70e676175c17bddc27 to your computer and use it in GitHub Desktop.
JavaScript extract salt from bcrypt hash
// the salt is the first 22 characters after the third '$'
// https://en.wikipedia.org/wiki/Bcrypt
const hash = '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy'
const salt = hash.split('$')[3].substr(0, 22)
console.log(salt) // N9qo8uLOickgx2ZMRZoMye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment