DEV Community

Mohana Vamsi
Mohana Vamsi

Posted on

Password Hashing in Python

One must never store passwords plainly. Let's learn the technique of hashing passwords securely using Python:

import hashlib

password = "securepassword"

hashed = hashlib.sha256(password.encode()).hexdigest()

print(f"Hashed password: {hashed}")

Hashing means that even if someone manages to break into the database, they will not get to know what the plaintext passwords are. Now, most modern systems use advanced algorithms like bcrypt, which also include salting.

Pro tip: Never ever roll out your own cryptographic stuff; it will lead you nowhere. Just use proven libraries like bcrypt or argon2.

This builds trust and makes the user secure.

Top comments (1)

Collapse
 
rouilj profile image
John P. Rouillard

Please don't use sha256 to hash password that will be stored. For hashing and storing passwords use something like: argon2, scrypt, bcrypt or pbkdf2.

Using sha256 for password hashing is rolling your own .

cheatsheetseries.owasp.org/cheatsh...