Introduction

User Authentication policy is a very crucial process for every application and organization. It is a process used to identify verified users and allow them to access accounts and networks securely. It is a process in which you verify that someone who is attempting to access services and applications is who they claim to be which can be established in various ways such as entering a password into your laptop or phone or a PIN number into your ATM. So far, we have built a web application that uses forms but we are still missing a major piece of basically almost every web application which is: USER AUTHENTICATION.

Implementing this is famously hard. There are many security concerns so its not advisable to do it yourself but with the help of Django which comes with a powerful built-in user authentication system that we can use, its much more easier.

How does this work?

Whenever we create a new project, by default, Django installs the auth app which provides us with a User Object containing:

  • Username
  • Password
  • Email
  • first_name
  • last_name

We will then use the User Object to implement log in, log out and sign up in our blog application.

Log In

Django already provides us with a default view for login page via LoginView so all we have to do is add a url pattern for the auth system, a log in template, and a small update to our settings.py file.

First, we will update the blog_project/urls.py where we will place our log in and log out pages at the accounts/URL.

ALSO READ  A Developer's Tool: The Hypertext Markup Language(HTML).

blog_project/urls.py

from django.contrib import admin

from django.urls import path, include

urlpatterns = [

path(‘admin/’, admin.site.urls),

path(‘accounts/’, include(‘django.contrib.auth.urls’)), # new

path(”, include(‘blog.urls’)),

]

Author