Back to Home

xv6 Login System

Salted password hashing + shadow-style storage + privilege drop into a user shell

Start: November 2025 • End: November 2025

xv6 login system

Project Overview

For a course called CS 3210, Design of Operating Systems, I implemented a user-space login system in C language that boots into a login prompt, verifies their credentials using salted SHA-256 password hashes, and then drops privileges with setuid(uid) before launching a shell.

The design mirrors the classic Unix credential storage: a public user database for name-to-UID mapping, along with a restricted shadow-style file that stores password hashes and salts for each user.

Demo Flow

The login flow is wired into init so a session is restarted when it exits.

xv6 console
init: starting login

xv6 login: huy
User not found. Create with a password: ********

init: starting login

xv6 login: huy
password: ********
# (shell launches under the authenticated uid)
  • If the username doesn’t exist, the program prompts to create a new user and stores credentials.
  • If the username exists, it prompts for a password and verifies by recomputing the salted hash.
  • On success, it calls setuid(uid) and exec("sh") to run the shell as that user.

Architecture

system flow
init (user-level)  →  exec("login")
login             →  reads /etc/users + /etc/shadow
                 →  verify sha256(password || salt)
                 →  setuid(uid)
                 →  exec("sh")
  • Boot integration: init starts the login program (and restarts it via fork/exec).
  • Separation of concerns: /etc/users is identity mapping; /etc/shadow is credential material.
  • Privilege boundary: login runs with enough privilege to manage credentials, then drops to the user before launching the shell.

Implementation Touchpoints

  • login_init.c – wires login into init (fork/exec loop) and runs initialization at boot.
  • login.c – interactive login UX (create-user path vs. password prompt).
  • login_lib.c – credential store, DRBG + salt generation, hashing, verification, and privilege drop.
  • login_design.md – design writeup (security mechanisms + file layout).

Tradeoffs & Notes

  • The entropy source is intentionally limited by the teaching OS environment; the DRBG is designed around what xv6 exposes.
  • Password input is via console (no masking in this environment).
  • Lab-default root provisioning improves usability; in production you’d use a reset/onboarding flow instead of a fixed default.

Design Doc (Full)