Skip to content

Implements a very simple user authentication system with registration and login features. It uses MySQL for database management, allowing users to register by providing details like username, password, and email and essential database migrations and connections of backend process.

Notifications You must be signed in to change notification settings

AntoJebi7/Django_Essentials_with_SQL_DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django with MYSQL DB for User Authentication and Dynamic Resources

Project Setup

Prerequisites

  • Python (version 3.7 or higher)
  • Django (version 3.x or higher)
  • pip (Python package installer)
  • Virtual environment tool (optional but recommended)

Installation

  1. Clone the Repository:

    https://github.com/AntoJebi7/Django_Essentials_with_SQL_DB.git
  2. Create a Virtual Environment (Optional but recommended):

    python3 -m venv env
    source env/bin/activate  # On Windows use `env\Scripts\activate`
  3. Install Dependencies: Install Django and other dependencies from requirements.txt:

    pip install -r requirements.txt
  4. Create a Django Project: If you haven’t already created the Django project:

    django-admin startproject myproject .
  5. Run Migrations:

    python manage.py migrate
  6. Run the Development Server:

    python manage.py runserver

    Access the server at http://127.0.0.1:8000/.

Creating a New Django App

  1. Create an App:

    python manage.py startapp myapp
  2. Register the App: Add your app to the INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        # Other apps...
        'myapp',
    ]
  3. Create Initial Migrations:

    python manage.py makemigrations myapp
  4. Apply Migrations:

    python manage.py migrate

Django User Authentication System

This project demonstrates a user authentication system in Django, including registration and login functionality with password hashing. This README outlines the setup process, database configuration, and important Django commands.

Table of Contents

  1. Introduction
  2. SQL Database Creation
  3. Django Setup
  4. User Registration Process
  5. Login Process
  6. Password Hashing
  7. Django Commands for Migration
  8. Important Topics

Introduction

This project sets up a Django application that allows users to register and log in. The registration process includes password hashing for security. Successful login redirects users to a designated blog page.

SQL Database Creation

  1. Install MySQL:

    • Ensure MySQL Server and MySQL Workbench are installed on your system.
  2. Create a Database:

    • Open MySQL Workbench and run the following SQL command to create a new database:

      CREATE DATABASE mydatabase;
  3. Configure Django to Use MySQL:

    • Update your Django project's settings.py file to configure the database settings.

Django Setup

  1. Install Dependencies:

    • Install Django and MySQL client library using pip:

      pip install django mysqlclient
  2. Create a Django Project:

    • Create a new Django project:

      django-admin startproject myproject
  3. Create a Django App:

    • Inside the project directory, create a new Django app:

      python manage.py startapp registration

User Registration Process

  1. Define the Model:

    • In the registration app, define the Registration model with fields for username, password, etc.
  2. Create a Registration Form:

    • Create a Django form for user registration in the registration/forms.py file.
  3. Implement the Registration View:

    • Create a view to handle user registration, validate the form, and save user details.
  4. Create a Registration Template:

    • Design an HTML template for the registration form.

Login Process

  1. Implement the Login View:

    • Create a view to handle user login, validate username and password, and handle redirects.
  2. Create a Login Template:

    • Design an HTML template for the login form.

Password Hashing

  1. Hash Passwords During Registration:

    • Use Django’s make_password to hash passwords before saving them to the database.
  2. Verify Passwords During Login:

    • Use Django’s check_password to verify user passwords during login.

Django Commands for Migration

  1. Create Migrations:

    • Generate migration files for your models:

      python manage.py makemigrations
  2. Apply Migrations:

    • Apply the migrations to create database tables:

      python manage.py migrate
  3. Create a Superuser (optional):

    • Create a superuser account to access the Django admin interface:

      python manage.py createsuperuser

Important Topics

  • Password Hashing: Ensures passwords are stored securely in the database.
  • User Authentication: Validates user credentials during login.
  • Django Migrations: Manage changes to the database schema.

About

Implements a very simple user authentication system with registration and login features. It uses MySQL for database management, allowing users to register by providing details like username, password, and email and essential database migrations and connections of backend process.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published