JavaScript / ECMAScript

bcrypt Password Hash in JS

Match bcrypt password hashes in their canonical $2a$/$2b$/$2y$ prefixed format.

Try it in the JS tester →

Pattern

regexJS
\$2[abxy]?\$\d{2}\$[./A-Za-z0-9]{53}   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\$2[abxy]?\\$\\d{2}\\$[./A-Za-z0-9]{53}", "g");
const input = "$2a$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

Version prefix $2 with optional suffix letter, cost parameter (two digits), salt + hash encoded in bcrypt's base64 alphabet for a fixed 53 trailing characters.

Examples

Input

$2a$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW

Matches

  • $2a$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW

Same pattern, other engines

← Back to bcrypt Password Hash overview (all engines)