Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Python Backend #4: Add Basic Auth to Your Flask API

923 views on YouTube

๐Ÿ” Build a secure login system with Flask + SQLite!
In this video, we add a basic user system to our API โ€” allowing registration and login using hashed passwords. This is the foundation of authentication in any backend.
Previous Video: https://youtu.be/UqH77WhRLH0
Previous Python build file: https://github.com/NDCSwift/Swift-Projects/raw/refs/heads/main/Python-Projects/PythonBackend3.zip
๐Ÿ”ง What Youโ€™ll Learn:
โœ… How to create a users table
โœ… How to hash passwords with hashlib
โœ… How to register users securely
โœ… How to verify login credentials
โœ… How to handle errors & conflicts

๐Ÿ›  Tools Used:
Python 3
Flask
SQLite (built-in)
VS Code
DB Browser for SQLite

Postman Register / Login
{
“username”: “testuser”,
“password”: “secure123”
}

๐Ÿ”ฅ Download My Project Files
๐Ÿ‘‰ Get the source code here:
๐Ÿ”— https://ndcswift.github.io/Swift-Projects/

โฑ๏ธ Timestamps:
00:00 โ€“ Intro & goals
00:44 โ€“ Updating our imports
01:08 โ€“ updating our init to support users
02:32 โ€“ Creating the /register route
04:00 โ€“ Creating a hashed password
07:08 โ€“ Creating the /login route
10:45 โ€“ Quick Bug / typing fixes
11:17 โ€“ Testing user flows with Postman
11:35 โ€“ Checking hashed passwords
13:27 โ€“ Outro & What’s next