User model with password
📖 Scenario: You are building a simple Flask app that needs to store user information securely. You want to create a user model that keeps usernames and hashed passwords.
🎯 Goal: Create a Flask user model class called User with attributes for username and password_hash. Implement a method to set the password by hashing it and a method to check a password against the stored hash.
📋 What You'll Learn
Create a
User class with username and password_hash attributesAdd a method
set_password(password) that hashes the password and stores it in password_hashAdd a method
check_password(password) that returns True if the password matches the stored hashUse
werkzeug.security functions generate_password_hash and check_password_hash💡 Why This Matters
🌍 Real World
Web applications need to store user passwords securely to protect user accounts and data.
💼 Career
Understanding how to hash and verify passwords is essential for backend developers working on user authentication.
Progress0 / 4 steps