Password Reset

View saved

Goal

This snapshot advances Junction Almanac by teaching you to send expiring one-use password reset links.

Every numbered folder is a complete Rails application. Run this stage independently, then compare it with the previous snapshot to isolate the new responsibility.

Prerequisites

Use Ruby 3.1 or newer, Bundler, PostgreSQL through Docker, and a terminal. Basic Ruby, HTML, and SQL vocabulary will make the framework conventions easier to recognize.

The app listens on port 3000. PostgreSQL is exposed on host port 5434, and every snapshot names a different database so lesson data never leaks between stages.

  • Ruby and Bundler
  • Docker with Compose
  • A code editor and terminal

Concepts

A secure reset stores only a bcrypt digest of a random token, checks a short expiry, returns the same request response for known and unknown emails, and clears the digest after use.

Keep the Rails request path visible: the router selects a controller action, Active Record handles data rules, and an ERB view renders the response inside the shared layout.

Walkthrough

Generate a token, enqueue a mailer, validate its digest and timestamp on edit/update, change the password, and invalidate the token.

Read the focused example, then inspect the matching repository snapshot for the surrounding configuration, validation, failure paths, and accessible markup.

token = SecureRandom.urlsafe_base64(32)
update!(password_reset_digest: BCrypt::Password.create(token),
        password_reset_sent_at: Time.current)

Run and verify

Enter 11-Password-Reset, install its bundle, prepare its database when this stage uses one, and start Rails on port 3000.

Open http://localhost:3000. Keep the server log visible so you can connect each browser action to its route, SQL query, rendered view, redirect, or validation error.

git clone https://github.com/michaeldunga1/fcc-rails-blog.git
cd fcc-rails-blog/11-Password-Reset
docker compose -f ../docker-compose.yml up -d
bundle install
bin/rails db:prepare db:seed
bin/rails server -p 3000

Troubleshooting

Development writes messages to tmp/mails in this snapshot. Production needs a real provider and stable host settings for absolute links.

If Rails reports a missing table, run bin/rails db:prepare db:seed in the current snapshot. Connection failures usually mean PostgreSQL is stopped or port 5434 is already occupied.

  • Read the first exception first
  • Confirm the current numbered folder
  • Never commit secrets or config/master.key

Try this

Request two links, use the newest one, confirm reuse fails, and confirm the old password no longer works.

Test one successful request and one invalid or unauthorized request. A production-minded Rails app must preserve data rules even when someone bypasses the visible links and submits a direct request.

  • Make one focused change
  • Verify it in the browser
  • Move on only after the checkpoint works

Next: Deploy

Comments

One comment per signed-in account. Comments are saved with this page’s URL.