Registration
Goal
This snapshot advances Cedarline Post by teaching you to validate accounts and store bcrypt password hashes.
Every numbered folder is a complete app. Run this stage independently, then compare it with the previous folder.
Prerequisites
Use Go 1.22+, a terminal, and a code editor. You should recognize packages, functions, and HTTP verbs.
Port 8081 must be free. Copy .env.example before starting. Stages from the data layer use a per-snapshot SQLite file (no Docker required).
- Go 1.22 or newer
- A code editor and terminal
- Optional: Docker only if you prefer another database later
Concepts
Registration normalizes email, checks uniqueness, and stores a one-way bcrypt hash—never a raw password.
Keep handlers thin: routes accept input, SQL and helpers enforce rules, and html/template escapes output by default.
Walkthrough
Accept a form POST, validate password length, hash with bcrypt, and save the user.
Read the example, then open the matching snapshot. The repository includes the surrounding setup and error handling.
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
db.Exec(`INSERT INTO users(...) VALUES(?,?,?,?)`, username, email, username, string(hash))
Run and verify
Enter 06-Registration, copy .env.example, run go mod tidy, and start the server on port 8081.
Open http://127.0.0.1:8081. Watch the terminal for validation and database errors.
git clone https://github.com/michaeldunga1/fcc-go-blog.git
cd fcc-go-blog/06-Registration
cp .env.example .env
go mod tidy
go run .
Troubleshooting
Duplicate username/email should return a clear form error instead of a 500.
Missing module errors usually mean go mod tidy was not run in this snapshot. For SQLite failures, delete a corrupt *.db file and restart so migrate/seed can recreate it.
- Read the first error first
- Restart after environment changes
- Never commit .env or *.db
Try this
Try a short password and a duplicate email.
Test a happy path and one invalid or unauthorized request.
- Make one small change
- Test it in the browser
- Compare with the next snapshot only after it works
Next: Login and Sessions
Comments
One comment per signed-in account. Comments are saved with this page’s URL.