Preparing your workspace
Passwords should be stored as strong one-way password hashes rather than plain text or reversible encrypted values.
Applications should never store user passwords as plain text. A password hashing algorithm transforms a password into a value that is designed to be difficult to reverse. During login, the submitted password is checked against the stored hash rather than decrypting a password. Modern application stacks commonly use dedicated password hashing functions such as Argon2 or bcrypt through trusted libraries. Password storage is only one part of authentication security; rate limiting, secure recovery flows, and session protection are also important.
A registration API can hash a user's password before storing the account record, and a login API can verify the submitted password against that hash.
const passwordHash = await bcrypt.hash(password, 12); const valid = await bcrypt.compare(password, passwordHash); console.log(valid);
The password is converted into a hash, and later the submitted password is checked against that hash.