Diagnose a bcrypt Password Over 72 Bytes
The bcrypt input limit used by most implementations is 72 bytes. Some libraries truncate longer input while others reject it. A password can exceed the limit with fewer than 72 characters when it contains multibyte text.
Worked example
Measure test strings at and beyond 72 bytes
const encoder = new TextEncoder();
for (const value of ["雪".repeat(24), "雪".repeat(25)]) {
const bytes = encoder.encode(value).length;
console.log({ bytes, overLimit: bytes > 72 });
}Steps
- Use synthetic data to reproduce the issue locally. Measure UTF-8 bytes with TextEncoder instead of using the string's length property.
- Check how the same library and version handle both hashing and verification at the boundary. In the example, 24 copies of 雪 use 72 bytes, while 25 use 75 bytes.
- If you maintain legacy bcrypt, avoid silently truncating new input. Confirm compatibility with existing accounts and plan any migration to a hashing algorithm suited to the application's password policy.
What to check
- Run the check against your application library: the linked demo uses bcrypt.js and can warn about truncation, while your backend may reject the same byte length.
- Use this demo with test strings only. Measure real input inside your application without printing passwords or modifying them to fit the limit.