// ── Hash before storing in DB ───────────────────────────────── $hashed = Password::hash($_POST['password']); QueryBuilder::table('users')::insert([ 'email' => $email, 'password' => $hashed, ]); // ── Verify on login ─────────────────────────────────────────── $user = QueryBuilder::table('users') ::where('email', $email) ::fetchOne(); if (!Password::verify($_POST['password'], $user->password)) { Response::simple(true, 'Incorrect email or password', 401); return; } // ── Validate strength before accepting from user ────────────── $errors = Password::validate($_POST['password']); if (!empty($errors)) { Response::simple(true, $errors[0], 422); return; } // ── Validate and confirm match in one block ─────────────────── if ($_POST['password'] !== $_POST['confirm_password']) { Response::simple(true, 'Passwords do not match', 422); return; } if (!Password::isStrong($_POST['password'])) { $errors = Password::validate($_POST['password']); Response::simple(true, $errors[0], 422); return; } // ── Rehash silently if cost setting has changed ─────────────── if (Password::needsRehash($user->password)) { QueryBuilder::table('users') ::where('id', $user->id) ::update(['password' => Password::hash($_POST['password'])]); } // ── Generate a temporary password for new staff accounts ────── $tempPassword = Password::generate(12); QueryBuilder::table('users') ::where('id', $userId) ::update(['password' => Password::hash($tempPassword)]); Notification::send($user, 'temp-password', ['password' => $tempPassword], ['email']); // ── Generate a reset token and store it ────────────────────── $token = Password::resetToken(); QueryBuilder::table('password_resets')::insert([ 'user_id' => $user->id, 'token' => hash('sha256', $token), 'expires_at' => AppDateTime::add(AppDateTime::now(), 'PT1H'), 'created_at' => AppDateTime::now(), ]);