Dashboard

What Is Password Hashing? What AI Login Code Gets Wrong

Password hashing stores a one-way fingerprint instead of the password itself. Here is what a good setup looks like and four mistakes AI-written login code makes.

Cecilia Iona
Cecilia Iona
Senior Editor, AI & Product
28 October 20261 min read

Password hashing is how a system stores a password without storing the password. The app runs the password through a one-way function and keeps only the result, called a hash. At login it hashes what you typed and compares the two. If the database leaks, the attacker gets hashes, not passwords.

The word "one-way" is the whole point. A hash cannot be run backwards to recover the original. Encryption can, which is why encrypting passwords is a mistake and hashing them is the standard.

Hashing versus encryption, in one line each

  • Encryption is reversible with a key. Use it for data you need to read again, such as a stored API token.

  • Hashing is not reversible. Use it for passwords, because the app never needs to know the password, only whether the attempt matches.

If your AI assistant wrote a login that can email a user their current password, it stored it reversibly. That is a defect, not a feature.

Why a plain hash is not enough

Fast hash functions like MD5 and SHA-256 were built to check file integrity quickly. Speed is a flaw here. An attacker with a stolen table of hashes can try billions of guesses per second on ordinary hardware. Two additions fix this.

A salt is a random value generated per user and mixed into the hash. Two people with the same password then have different hashes, and precomputed tables of common passwords become useless. According to the OWASP Password Storage Cheat Sheet, the salt is unique and randomly generated for every password, and most modern libraries create it automatically.

A work factor deliberately makes each hash slow and memory-hungry. A login takes a fraction of a second, which no user notices, while an attacker's guessing rate collapses.

That is why you use a purpose-built password hashing algorithm instead of a general hash.

Which algorithm to use

The OWASP cheat sheet currently ranks them like this:

  • Argon2id is the first choice. The headline minimum is 19 MiB of memory, 2 iterations, and 1 degree of parallelism.

  • scrypt if Argon2id is unavailable, with a much larger minimum memory cost (128 MiB at the recommended setting).

  • bcrypt for older systems, with a work factor of at least 10. It also ignores input beyond 72 bytes, so very long passwords need handling.

Check the cheat sheet itself when you set values, because the recommendations get revised as hardware improves. Hand-rolling any of this is the wrong move. Use the library your framework recommends.

A minimal example in Node with the argon2 package:

js
import argon2 from 'argon2';

// at signup
const hash = await argon2.hash(password, { type: argon2.argon2id });
await db.users.insert({ email, password_hash: hash });

// at login
const ok = await argon2.verify(user.password_hash, attempt);

The library generates the salt and stores it inside the hash string, so there is no separate salt column to manage.

Four mistakes to look for in AI-written login code

Code assistants usually get the happy path right and slip on the details. Search for these.

  1. A fast hash. Search the repo for md5, sha1, sha256, createHash. Any of them near a password is wrong. The fix is a password hashing library, not a different fast hash.

  2. A fixed or reused salt. A salt written as a string constant, or one derived from the username, defeats the purpose. It must be random per user.

  3. Comparing with a plain equality check. Libraries provide a verify function for a reason. Writing hash(attempt) === stored by hand risks timing differences and breaks as soon as parameters change.

  4. Passwords in logs or errors. Search for console.log and logger calls near the login handler. A debug line that prints the request body writes every password to your log files in plain text.

A fifth habit is worth adding: ask the assistant to explain how it stores passwords before you accept the code. If the answer mentions a database column called password rather than password_hash, stop and look. For work on auth code in general, the guide to letting an AI coding agent touch your auth code lists what to review by hand.

What hashing does not protect against

A strong hash slows guessing of weak passwords but does not make them strong. It also does nothing about phishing, reused passwords, or a compromised server that sees the password before hashing it. That is why modern apps pair hashing with two-factor authentication or drop passwords entirely with passkeys or magic links. Account recovery is the other weak point, covered in adding password reset.

If you want the bigger picture on where AI-built apps go wrong, the AI risks guide is the starting point.

Frequently asked questions

What is the difference between hashing and encryption?

Encryption can be reversed with a key. Hashing cannot be reversed. Passwords should be hashed, because the app only needs to check a match.

Is bcrypt still safe to use?

Yes, with a work factor of at least 10 according to OWASP, and with attention to its 72-byte input limit. Argon2id is the preferred choice for new systems.

What is a salt in password hashing?

A random value, unique per password, that is combined with the password before hashing. It means identical passwords produce different hashes and stops precomputed lookup tables from working.

Can a hashed password be cracked?

Not reversed, but guessed. Attackers hash likely passwords and compare. A slow algorithm and a unique salt make each guess expensive, and a long, unique password makes success unlikely.

How did this land?

About the author

Cecilia Iona
Cecilia Iona

Senior Editor, AI & Product

Cecilia leads the Swarmz editorial desk. She has spent a decade turning complex AI and product topics into writing people actually finish, and she owns the blog's quality bar.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.