Toolypet
Back to Blog
Security

SHA-256 vs bcrypt vs Argon2 - Complete Hashing Algorithm Comparison for Developers

Learn why you shouldn't use SHA-256 for password storage, the differences between bcrypt and Argon2, and the recommended hashing strategy for 2026.

Toolypet Team

Toolypet Team

Development Team

7 min read

SHA-256 vs bcrypt vs Argon2: When Should You Use What?

"If I hash passwords with SHA-256 and store them, it should be secure, right?"

Many developers ask this question. The conclusion is: you should not use SHA-256 for passwords.

This guide explains the differences between hashing algorithms and the correct choice for each situation.


Hashing vs Encryption: Basic Concepts

Hashing

Input → Hash Function → Fixed-length Output (irreversible)

"password" → SHA-256 → "5e884898da28047d..."
  • One-way: Cannot recover original
  • Deterministic: Same input = Same output
  • Fixed length: Output size independent of input size

Encryption

Input + Key → Encryption → Ciphertext → Decryption + Key → Original

"password" + key → AES → "Xyz..." → AES + key → "password"
  • Two-way: Original recoverable with key
  • Key-dependent: Cannot decrypt without key

Use hashing for password storage. You don't need the original - just compare input value with hash.


Hashing Algorithm Classification

Fast Hash

AlgorithmOutput LengthSpeedUse Case
MD5128 bitsVery fast❌ Do not use for security
SHA-1160 bitsFast❌ Do not use for security
SHA-256256 bitsFastFile integrity, digital signatures
SHA-512512 bitsFastFile integrity, blockchain

Slow Hash (Password Hash)

AlgorithmFeatures2026 Recommendation
bcryptAdjustable time (cost)
scryptMemory-intensive
Argon2Latest, OWASP #1✅✅
PBKDF2High compatibility⚠️ Legacy

Why Shouldn't You Store Passwords with SHA-256?

Reason 1: Too Fast

SHA-256 is designed for speed. This is an advantage for file integrity checks, but a fatal flaw for password storage.

Modern GPU performance:
- MD5: 180 billion hashes/sec
- SHA-256: 10 billion hashes/sec
- bcrypt (cost 12): 1,000 hashes/sec

Even an 8-character complex password can be cracked in minutes when stored with SHA-256.

Reason 2: Manual Salt Management Required

# ❌ Wrong approach
hash = sha256(password)

# Problem: Vulnerable to Rainbow Table attacks

# ⚠️ Improved but still insufficient
salt = generate_random_salt()
hash = sha256(salt + password)

# Problem: Still too fast

Reason 3: GPU Acceleration Vulnerability

SHA-256 is easily parallelized on GPUs. Attackers can calculate hashes at tremendous speed with just a few gaming GPUs.


bcrypt: 27 Years of Proven Standard

How It Works

bcrypt(cost, salt, password) → hash

cost: Number of computation iterations (2^cost)
salt: 22-character random string (auto-generated)

Why Is bcrypt Safe?

  1. Intentionally slow: Speed controlled by cost factor
  2. Automatic salt: Different hash every time
  3. Memory-intensive: Difficult to GPU accelerate

Cost Factor Guide (2026)

CostHash TimeRecommended Use
10~100msDevelopment/testing
12~250msGeneral web apps (recommended)
13-14~500msHigh security requirements
15+1sec+Special purposes

Code Examples

// Node.js with bcrypt
const bcrypt = require('bcrypt');

// Hashing (signup)
const hash = await bcrypt.hash(password, 12); // cost 12

// Verification (login)
const isValid = await bcrypt.compare(inputPassword, storedHash);
# Python with bcrypt
import bcrypt

# Hashing
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))

# Verification
is_valid = bcrypt.checkpw(input_password.encode(), stored_hash)

Argon2: The Next-Generation Standard

What Is Argon2?

Winner of the 2015 Password Hashing Competition. It's the #1 recommended algorithm by OWASP for 2026.

Argon2 Variants

VariantFeaturesRecommendation
Argon2dGPU attack resistantSide-channel vulnerable
Argon2iSide-channel resistantGPU attack vulnerable
Argon2idd + i hybrid✅ Recommended

Argon2 Parameters

Argon2id(memory, iterations, parallelism, password, salt)

- memory: Memory usage (KB)
- iterations: Number of iterations
- parallelism: Number of parallel threads

OWASP Recommended Settings (2026)

Minimum settings:
- memory: 64MB (65536 KB)
- iterations: 3
- parallelism: 4

High security:
- memory: 256MB
- iterations: 4
- parallelism: 8

Code Examples

// Node.js with argon2
const argon2 = require('argon2');

// Hashing
const hash = await argon2.hash(password, {
  type: argon2.argon2id,
  memoryCost: 65536, // 64MB
  timeCost: 3,
  parallelism: 4
});

// Verification
const isValid = await argon2.verify(storedHash, inputPassword);
# Python with argon2-cffi
from argon2 import PasswordHasher

ph = PasswordHasher(
    memory_cost=65536,
    time_cost=3,
    parallelism=4
)

# Hashing
hash = ph.hash(password)

# Verification
try:
    ph.verify(stored_hash, input_password)
except VerifyMismatchError:
    # Password mismatch

bcrypt vs Argon2: Which to Choose?

Comparison Table

ItembcryptArgon2id
Age1999 (27 years)2015 (11 years)
Validation27 years field-provenAcademically validated
Memory tuning
GPU resistance⚠️ Medium✅ Strong
LibrariesAll languagesMost languages
OWASP ranking#2#1

Selection Guide

Choose bcrypt:

  • Legacy system compatibility needed
  • Proven stability preferred
  • Simple configuration preferred

Choose Argon2id:

  • Starting new project
  • Following latest security standards
  • High GPU resistance needed

2026 Recommendation Order (OWASP)

#1: Argon2id
#2: bcrypt
#3: scrypt
#4: PBKDF2 (when compatibility needed)

When to Use SHA-256

SHA-256 is perfect for purposes other than passwords.

Suitable Use Cases

Use CaseExample
File integrityDownload verification, backup confirmation
Digital signaturesJWT, certificates
BlockchainBitcoin mining
ChecksumsData transmission verification
Hash tables(with HMAC) API key storage

Code Example

// File hash (Node.js)
const crypto = require('crypto');
const fs = require('fs');

const fileBuffer = fs.readFileSync('file.zip');
const hash = crypto.createHash('sha256').update(fileBuffer).digest('hex');

console.log(hash); // "a1b2c3d4..."

Practical Implementation Checklist

Password Storage

  • Use Argon2id or bcrypt
  • Set appropriate work factor (250-500ms)
  • Use library auto salt generation
  • Store complete hash result (including salt)

Password Verification

  • Use timing-attack-safe comparison functions
  • Consistent response time on verification failure
  • Limit failed login attempts

Migration

  • Gradual upgrade to new hash
  • Re-hash with new algorithm on successful login
  • Use prefix to identify old hashes

FAQ

Q1: How do I handle existing passwords stored with MD5?

A: Re-hash with the new algorithm when users log in.

// On successful login
if (hash.startsWith('$md5$')) {
  // Re-hash with bcrypt
  const newHash = await bcrypt.hash(inputPassword, 12);
  await updateUserHash(userId, newHash);
}

Q2: Isn't bcrypt's 72-byte limit a problem?

A: Most passwords are within 72 bytes. For longer inputs, hash with SHA-256 first, then apply bcrypt.

// Handling long passwords
const prehash = crypto.createHash('sha256').update(password).digest('base64');
const finalHash = await bcrypt.hash(prehash, 12);

Q3: Doesn't a high cost factor make you vulnerable to DoS attacks?

A: Yes. Implement rate limiting on login requests. 250-500ms is the appropriate balance.

Q4: Is pepper necessary?

A: Pepper (application-level secret key) provides additional security but isn't required. Salt alone is sufficient.

Q5: Can I use online hash tools?

A: Use only for learning/testing purposes. In production, hashing must be done server-side. The Hash Generator is safe as it processes 100% client-side.


Conclusion

Use CaseRecommended Algorithm
Password storageArgon2id > bcrypt
File integritySHA-256
Digital signaturesSHA-256 / SHA-512
Legacy compatibilitybcrypt / PBKDF2

Key Principles:

  1. Never use fast hashes (SHA-256, MD5) for passwords
  2. bcrypt cost 12+, Argon2 memory 64MB+
  3. Use library-provided auto salt generation

Related Tools

ToolPurpose
Hash GeneratorGenerate SHA-256, bcrypt hashes
Password GeneratorGenerate strong passwords
securityhashingSHA-256bcryptArgon2encryptiondevelopment

About the Author

Toolypet Team

Toolypet Team

Development Team

The Toolypet Team creates free, privacy-focused web tools for developers and designers. All tools run entirely in your browser with no data sent to servers.

Web DevelopmentCSS ToolsDeveloper ToolsSEOSecurity