Customizing Phone Number Authentication in Django Last Updated : 21 May, 2025 Comments Improve Suggest changes Like Article Like Report We will implement phone number-based authentication in Django by creating a custom user model that uses phone numbers instead of usernames for login. You’ll learn how to build a custom user manager, update settings, and integrate the new user model with the Django admin panel to enhance security and streamline the authentication process.Create Project and AppPrerequisites: Django Introduction and Installation Creating a ProjectTo start the project use this commanddjango-admin startproject newtoncd newtonpython manage.py startapp accountsFile Structure:File StructureNote: Phone number authentication is a critical feature in modern web applications. To implement this and other advanced features, the Django Web Development Course will help you build secure and user-friendly systems.INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "accounts", //App name]Create the Custom User ModelIn accounts/models.py, define a custom user model that uses phone instead of username: Python from django.db import models from django.contrib.auth.models import AbstractUser from .manager import UserManager class GFG(AbstractUser): phone = models.CharField(max_length=12, unique=True) USERNAME_FIELD = 'phone' REQUIRED_FIELDS = [] objects = UserManager() Create a Custom User Manageraccounts/manager.py: We import BaseUserManager from django.contrib.auth.base_user to create a custom user manager.We define a custom UserManager class that extends BaseUserManager. This manager is responsible for creating and managing user instances.The create_user method is used to create a standard user with a phone number, an optional password, and any extra fields passed as keyword arguments. It checks if a phone number is provided and raises a ValueError if not. Python from django.contrib.auth.base_user import BaseUserManager class UserManager(BaseUserManager): use_in_migrations = True def create(self, phone, password=None, **extra_fields): if not phone: raise ValueError('Phone number is required') user = self.model(phone=phone, **extra_fields) user.set_password(password) user.save() return user def superuser(self, phone, password, **extra_fields): extra_fields.setdefault('is_staff', True) extra_fields.setdefault('is_superuser', True) extra_fields.setdefault('is_active', True) return self.create(phone, password, **extra_fields) Register the Model with AdminIn accounts/admin.py: Python from django.contrib import admin from .models import GFG admin.site.register(GFG) Update Django SettingsIn newton/settings.py, tell Django to use your custom user model: Python AUTH_USER_MODEL = "accounts.GFG" #Appname.model(classname) Run MigrationsMake and apply migrations for your custom user model:python manage.py makemigrationspython manage.py migrateRun the ServerStart the development server:python manage.py runserverOutputDjango Administration Comment More infoAdvertise with us Next Article Customizing Phone Number Authentication in Django prathamsahani0368 Follow Improve Article Tags : Python Geeks Premier League Django Geeks Premier League 2023 Practice Tags : python Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth 15+ min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p 11 min read Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list 10 min read Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test 9 min read Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co 11 min read Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam 3 min read Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes 9 min read Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We 9 min read Like