Sign-in hardening: lockout, stronger passwords, authenticator codes

- 10 failed sign-ins in a row (password, authenticator code, or password
  at signing) lock an account for 15 minutes from any address; the user
  is emailed; admins can unlock. Same message as a wrong password.
- Passwords: at least 12 characters (max 72), refused if found in Have I
  Been Pwned (k-anonymity range API; fails open; PWNED_PASSWORDS_CHECK=false)
- Optional TOTP (authenticator app) with 10 recovery codes for password
  and emailed-link sign-in, and at signing (auth method password_totp);
  codes accepted once; admins can reset; SSO sign-in unaffected
- Demo/test passwords updated; guide, README and procedures document

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 15:17:56 -05:00
1 parent a6bfe922be
commit 14316bb60f
41 files changed
+600 -45

No files matched your search

@@ -0,0 +1,12 @@
class AddSignInHardening < ActiveRecord::Migration[8.1]
def change
# Account lockout after repeated failed sign-ins (from any address).
add_column :users, :failed_sign_ins, :integer, null: false, default: 0
add_column :users, :locked_until, :datetime
# Authenticator app (TOTP) as a second factor for password sign-in.
add_column :users, :otp_secret, :text
add_column :users, :otp_enabled_at, :datetime
add_column :users, :otp_last_used_at, :integer # last accepted time step (no replays)
add_column :users, :otp_recovery_codes, :json
end
end
Generated
+7 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_11_08_040000) do
ActiveRecord::Schema[8.1].define(version: 2026_11_08_050000) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -792,6 +792,12 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_08_040000) do
t.datetime "last_signed_in_at"
t.boolean "reminder_emails", default: true, null: false
t.datetime "disabled_at"
t.integer "failed_sign_ins", default: 0, null: false
t.datetime "locked_until"
t.text "otp_secret"
t.datetime "otp_enabled_at"
t.integer "otp_last_used_at"
t.json "otp_recovery_codes"
t.index ["email_address"], name: "index_users_on_email_address", unique: true
t.index ["sso_uid"], name: "index_users_on_sso_uid", unique: true
end
+3 -3
View File
@@ -12,12 +12,12 @@ end
if ENV["DEMO"].present?
admin = User.find_or_create_by!(email_address: "admin@example.com") do |u|
u.name = "Demo Admin"
u.password = "password123"
u.password = "demo-password-123"
u.admin = true
end
pilot = User.find_or_create_by!(email_address: "pilot@example.com") do |u|
u.name = "Demo Pilot"
u.password = "password123"
u.password = "demo-password-123"
end
Current.session = admin.sessions.first_or_create!(user_agent: "seed", ip_address: "127.0.0.1")
@@ -87,5 +87,5 @@ if ENV["DEMO"].present?
e.signoff_person = "J. Mechanic A&P/IA 1234567"
end
puts "Demo data loaded. Sign in as admin@example.com / password123 (or pilot@example.com)."
puts "Demo data loaded. Sign in as admin@example.com / demo-password-123 (or pilot@example.com)."
end