If you've worked on any authentication system in the last decade, you've probably used bcrypt. It's been the go-to password hashing solution for years, and for good reason. But lately, Argon2 has been getting a lot of attention in the security community, and many developers are wondering if it's time to make the switch.
A Quick Background
Bcrypt was released in 1999 and has been a solid foundation for password hashing implementations across countless projects. It implements the Blowfish cipher with a salt and a cost factor, making it adaptable to increasing computational power. You've probably seen it in action with those $2a$
prefixed hashes in your database.
Argon2 emerged as the winner of the 2015 Password Hashing Competition, bringing some modern approaches to the table. It comes in three variants:
- Argon2d: Optimized for highest resistance to GPU cracking
- Argon2i: Focused on side-channel attack resistance
- Argon2id: A hybrid approach that most developers should probably use by default
What Makes Argon2 Stand Out?
Memory-Hardness
The biggest advantage Argon2 brings to the table is its memory-hard design. While bcrypt primarily focuses on CPU intensity, Argon2 requires a configurable amount of memory to compute hashes.
This is particularly effective against GPU-based attacks, as GPUs typically have limited memory compared to their computational power.
In practice, this means that even if an attacker has access to specialized hardware, they can't simply throw more computational power at the problem - they're bottlenecked by memory requirements.
Configurability
Argon2 exposes three key parameters:
- Memory cost
- Time cost (iterations)
- Parallelism factor
This gives developers more control over resource utilization compared to bcrypt's single cost factor. You can tune these parameters based on your specific requirements and hardware constraints. In my experience, this flexibility is particularly useful when deploying to different environments with varying resource profiles.
Where bcrypt Still Holds Strong
Production-Proven Reliability
After two decades of production use and security analysis, bcrypt has proven its reliability. Its implementation is well-understood, and its security properties have been thoroughly vetted. I've yet to encounter a case where properly implemented bcrypt has been the weak point in a system's security.
Implementation Availability
Bcrypt has mature, well-maintained implementations across all major programming languages and frameworks. While Argon2 support is growing, you might still run into situations where you need to implement additional libraries or wrappers, especially in more niche environments, in order to get it to work properly.
Making a Practical Decision
Here's what I consider when choosing between the two:
Argon2 Makes Sense When:
- You're building a new system and can fully control the environment
- Memory resources aren't a significant constraint
- You need granular control over resource utilization
- Side-channel attack resistance is a requirement (using Argon2i or Argon2id)
Stick with bcrypt When:
- You need broad language/framework compatibility
- You're working in memory-constrained environments
- You're maintaining or extending an existing system that already uses bcrypt effectively
- Your security requirements are well-served by CPU-hard hashing
Real-World Implementation Notes
When implementing either algorithm, there are some practical considerations to keep in mind:
# Argon2 implementation example
from argon2 import PasswordHasher
ph = PasswordHasher(
time_cost=2, # Number of iterations
memory_cost=65536, # Memory usage in kibibytes
parallelism=4 # Number of parallel threads
)
# bcrypt implementation example
import bcrypt
salt = bcrypt.gensalt(rounds=12) # Adjust cost factor based on hardware
Both implementations require careful parameter tuning based on your specific hardware and security requirements. I typically benchmark these on production-equivalent hardware to find the sweet spot between security and performance.
Conclusion
Is Argon2 technically superior to bcrypt? From a design perspective, yes. Its memory-hard properties and additional parameterization provide better protection against modern attack vectors. However, bcrypt remains a solid choice that's more than adequate for many applications.
For new projects, I generally recommend Argon2id unless there are specific constraints that would make bcrypt a better fit. The memory-hardness feature alone makes it more resistant to the types of attacks we're seeing more frequently these days.
However, if you're maintaining a system that uses bcrypt correctly, there's no pressing need to migrate. Both algorithms, when properly implemented and configured, provide strong security for password hashing. The key is choosing the right parameters for your use case and implementing the algorithm correctly.
Remember: The biggest security risks usually aren't from choosing between two strong hashing algorithms, but from implementation mistakes or poor parameter selection. Focus on getting those right first.
Walter Guevara is a Computer Scientist, software engineer, startup founder and previous mentor for a coding bootcamp. He has been creating software for the past 20 years.
Last updated on: