liveBook · Manning

Bcrypt

As explained in Build Python Web Apps with Streamlit

bcrypt is a password-hashing library and algorithm implementation designed to make password guessing computationally expensive.

bcrypt protects user passwords by storing computationally expensive hashes instead of the original passwords. If a database leaks, the stored hash cannot simply be entered into the application as the password. section 8.3.2

Hash and verify a password

Install bcrypt with pip, then hash a password with bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode(). The random salt helps defend against rainbow-table lookups. During login, bcrypt.checkpw compares the entered password with the stored hash and returns True when they match. section 8.3.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains hashing, salts, and password comparison practically, while deferring bcrypt's internal algorithm details.
Examples
Uses a Python User class, bcrypt methods, a signup form, and a database row containing a password hash.
What you can do after
Apply bcrypt to hash passwords during account creation and verify them during authentication.
How it connects
Connects password hashing with authentication, salted hashes, databases, user services, and account creation.

Also explained in

Compare how 3 books explain bcrypt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.