Set up send_mail.py by adding sender's email address and app password (Only work for Gmail accounts). Install flask, wtf-flask, and other necessary modlues
This is a simple Flask-based web application that implements Two-Factor Authentication (2FA) using email for additional security during user login. When a user attempts to log in, a unique authentication code is sent to their email, which must be entered to complete the login process.
- Flask
- Flask-Login
- smtplib (Python standard library)
You can install the necessary dependencies by running the following command:
pip install Flask Flask-Login
If you're using Gmail to send the 2FA code, you'll need to create an App Password.
- Go to your Google Account Settings.
- Under the Security section, turn on 2-Step Verification (if you haven’t already).
- Create an App Password for sending emails.
After you have the app password, add the email sender (your Gmail address) and the generated app password to the sendmail.py
file.
# sendmail.py
sender_email = "your-email@gmail.com"
app_password = "your-app-password"
Start the Flask application by running the following command:
python web.py
- The application uses Flask-Login for session management and user authentication built from scratch.