Password

Building a Simple Password Manager Using Python, SQLite, and Django

Objective

To create a simple web-based password manager that allows users to securely store and manage their passwords.

Table of Contents

Requirements

  • Intermediate understanding of Python
  • Familiarity with HTML, CSS, and basic web development
  • Python 3.x installed
  • Django installed (pip install Django)

Packages Needed

Verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django:

Python
>>>import django
>>>print(django.get_version())
4.2

Steps

Step 1: Set Up Django Project and App

Open shell terminal and create a new Django project:

Bash
django-admin startproject PasswordManager

Inside the project directory, create a new app:

Bash
python manage.py startapp mypasswords

In root project folder “PasswordManager”, following three items will be created:

+ mypasswords

+ PasswordManager

mangage.py

Step 2: Configure Database

Django comes with SQLite, so you don’t need to install it separately. Update PasswordManager/settings.py to make sure your app is included in INSTALLED_APPS.

Python
# PasswordManager/settings.py

INSTALLED_APPS = [
    # ...
    'mypasswords',
]

Step 3: Create Models

Define the models in models.py inside your app folder.

Python
# mypasswords/models.py

from django.db import models

class Password(models.Model):
    website = models.CharField(max_length=100)
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)

Run the migrations to create the database schema:

Bash
python manage.py makemigrations
python manage.py migrate

Step 4: Create Views and Templates

  1. Create a new folder called templates inside your app folder and add an HTML file index.html.
  2. In views.py, add the logic for fetching and storing passwords.
Python
# mypasswords/views.py

from django.shortcuts import render, redirect
from .models import Password

def index(request):
    if request.method == 'POST':
        website = request.POST['website']
        username = request.POST['username']
        password = request.POST['password']
        new_entry = Password(website=website, username=username, password=password)
        new_entry.save()
        return redirect('index')
    else:
        passwords = Password.objects.all()
        return render(request, 'index.html', {'passwords': passwords})

Step 5: Create Forms in HTML

Add form fields in index.html to input website, username, and password.

HTML