Django registration with confirmation email and two factor authentication using the google authenticator app
This is a django application created using Django 1.10 and python 3.6. The project has extended django authentication and I have implemented the ability for user to register, after a given user register in our web app, we send an email for user to click a link and confirm they control the email used during registration. The project has also implemented the ability to enable two factor authentication using Google Authenticator App
- Clone the project using git clone https://github.com/henrymbuguak/django-email-confirmation-and-two-factor-authentication-using-the-google-authenticator-app.git
- Create a python virtual environment using: mkvirtualenv --python=/usr/bin/python3.4 mysite-virtualenv this command will create a virtual environment name mysite-virtualenv and activate it. Learn more about python virtualenv
- Navigate to the project root directory on your terminal, This where manage.py file is located in this folder your see a file named requirements.txt This file holds the dependency of this project.
- To install the project dependency use this command on your terminal: pip install -r requirements.txt
- The next step is to run the migrations, for simplicity we are going to use sqlite database that comes with python.
- On your terminal run this command: python manage.py makemigrations. Learn more about django migration system
- The next step is to apply the migrations by using: python manage.py migrate
- In order for django to send emails, you need to configure email configurations in settings.py file. In settings.py there is this section:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youremail@mail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
- After filling the email configuration, run the development server using: python manage.py runserver
To test the functionality of this project, visit HenryLab demo site
- Register using a valid email address
- After registering, the system will send you a confirmation email.
- Login into email account an click on confirmation link.
- The system will automatically log you in and you will be in your dashboard.
- Inside your dashboard you will see the button named Enable or Disable two factor authentication
- Click on the button and follow the instruction on how to enable two factor authentication.
- After enabling two factor authentication logout and login again to test the functionality.
NB Remember you need Google Authenticator App app on your phone to scan QR code.