liveBook · Manning

Authentication

As explained in Build Python Web Apps with Streamlit

User authentication is the process of verifying a person's identity before granting access to an account or application resources.

Authentication verifies a person's identity before allowing access to an account or its resources. In a CRUD application, it connects account creation, login, logout, and private data management. section 8.1.1 section 8.1.2

A practical authentication flow typically includes:

Keep user-related logic in a UserService. Its get_authenticated_user method looks up the username, asks the User object to authenticate the password, returns the user on success, and returns None otherwise. The login page stores logged_in and the authenticated user in Streamlit session state, then displays a success or error message. section 8.4.2

A failed login

If the username does not exist or the password is incorrect, authentication returns None and the interface shows “Invalid username or password.” The implementation deliberately uses the same result for both cases, although distinguishing them can matter in other designs. section 8.4.2

Figure 8.1 Rough sketches of the pages we want in Haiku Haven

Use the page sketches to compare signup, login, logout, and logged-in CRUD experiences before implementing the interface. section 8.1.2

Never store passwords as plain text. Hash passwords with a library such as bcrypt, store the resulting hash, and compare it with a hash of the supplied password during authentication. Advanced security features remain outside this basic implementation. section 8.7 section 8.1.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains credential lookup, password-hash comparison, return values, and session state, while deferring advanced security.
Examples
Uses Haiku Haven signup and login pages, UserService methods, password fields, session flags, and visible success or error messages.
What it assumes
Assumes basic familiarity with Streamlit while introducing authentication through signup, login, UserService, and session-state examples.
What you can do after
Build a basic authenticated Streamlit flow with UserService, hashed passwords, session state, and private user-specific records.
How it connects
Connects authentication with CRUD operations, password hashing, session state, data storage, and multi-page applications.

Also explained in

Compare how 34 books explain authentication →

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.