This Flask application demonstrates user authentication using JWT tokens. Users can sign up, log in, view protected content, and log out.
- Sign Up: Register new users with a unique username and password.
- Log In: Authenticate users and generate a JWT token stored in a cookie.
- Protected Page: Access a protected page that displays a list of registered users.
- Log Out: Clear the JWT token from the cookie to log out.
- Flask: Web framework for Python.
- Flask-SQLAlchemy: Flask extension for SQLAlchemy, an SQL toolkit and ORM.
- Werkzeug: Library for password hashing and authentication utilities.
- JWT (JSON Web Tokens): For secure authentication token generation and verification.
- Python 3.x
- Flask
- Flask-SQLAlchemy
- Werkzeug
- JWT (JSON Web Tokens)
- SQLite
-
Clone the repository:
git clone https://github.com/dhairyagothi/50_days_50_web_project.git cd 50_days_50_web_project/public/flask_auth_app
-
Install dependencies:
pip install -r requirements.txt
- Set up your Flask application:
- Set
SECRET_KEY
inapp.py
for JWT token encryption. - Configure
SQLALCHEMY_DATABASE_URI
inapp.py
for your database.
- Set
-
Initialize the database:
python from app import db db.create_all() exit()
-
Run the Flask application:
python app.py
-
Open your web browser and go to http://localhost:5000 to access the application.
- Sign Up: Navigate to http://localhost:5000/signup to create a new user account.
- Log In: Navigate to http://localhost:5000/login to log in with your credentials.
- Protected Page: After logging in, you can access http://localhost:5000/protected to view the list of users.
- Log Out: Click on the "Sign Out" button to log out from the application.