shadcn.io is not affiliated with official shadcn/ui
Change Password Dialog Block for React
A password manager's account page with its change-password dialog shown open: three password fields, a live checklist of five rules with a strength meter, a match line, and an Update button that stays quiet until every rule passes.
Installation
Overview
Let people change a password without guessing what it needs, with this dialog for React with Base UI. It opens from the Account page of Cipherwick, a password manager: the header holds an outline Change password Button, and the page itself is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The Dialog holds three Password Inputs, the current password, the new one and its repeat, each in a Field with its own show button. Under the new password a five-step meter and a checklist follow your typing: at least 12 characters, upper and lower case, a number, a symbol, and not the current password. Each rule changes shape when it is met and says so in words, and a line under the repeat says whether the two match. Update password, the only Shine Button, stays quiet until every rule passes; pressed too early it names the first thing missing and goes there. On success the drawn password row reads Updated in this demo and focus returns to Change password. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same fields and the same checklist. For account settings, vaults, admin consoles and any app that holds a password.
FAQ
Why is the dialog already open, and what do I keep?
So you can see it without a click. On load the dialog is a copy drawn in place over the page: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Change password button opens the real Dialog, modal, with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same PasswordFields component and share the block's state, so what you typed in the copy is there in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How do the rules and the meter work?
RULES lists the five rules and metOf says which a password meets, so the checklist, the meter and the word beside it all come from one source: the meter fills one step per rule, from Weak through Fair and Good to Strong. A rule's glyph changes shape when it is met, a ring becoming a tick, and its words carry the state too ("met", "not met"), so colour is never the only signal. The checklist is not a live region, which would chatter at every key. About 600 ms after you stop typing, one polite message gives the word, the count and whether the two new passwords match. Change the rules to your own policy; keep the checklist and the server's check the same list.
What does Update password do here, and how do I wire it up?
Here it changes nothing: the current password isn't compared with anything and nothing is stored or sent. Update closes the dialog, the drawn password row reads Updated in this demo, a polite status message says nothing was stored, and focus returns to Change password. In your app send both passwords to your server in update, check the current one there, keep the dialog open with a busy state until it answers, and show a wrong current password in that field's own message. Re-check every rule on the server, since the browser's checks can be skipped.
Why is the button quiet instead of disabled?
A disabled button leaves the tab order and says nothing about why. Here Update password is aria-disabled while anything is missing, so it can still be reached, and pressing it, or pressing Enter in a field, shows the first missing thing in one reserved line that never moves the buttons and puts focus on the field it belongs to. Editing any field clears the line.
Is it accessible from the keyboard?
Yes. The real dialog is named by its title and described by its sentence, focus starts in the current password field and stays inside until it closes, and Escape, Cancel and the close button all return focus to Change password. Each field is named by its label, with the autofill hints that let a password manager fill the current password and offer a new one, and each show button is a tab stop that Enter and Space toggle. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. The copy shown on load moves no focus; Escape inside it, Cancel and its close button close it and put focus on Change password.
How does it look on a phone?
The copy shown on load docks to the foot of the frame as a bottom sheet, its actions pinned at the bottom, and the fields scroll above them; the checklist is one column. The real dialog keeps the Dialog's own phone layout, a sheet from the bottom that scrolls inside itself.
Related
- Pro
Change Password Account
Sign-in methodsA change-password form that says what it ends: three password fields with a line naming what the new one still needs, boxes for the other sessions, an app password and trusted devices, and a sentence that follows them.
- Pro
Password Re-Entry Confirm Dialog
Destructive confirmsA hosting dashboard with an alert dialog shown open that asks for the password again before a project is deleted: a lock tile, one field, a Caps Lock note, a count of tries and a destructive confirm.
- Pro
Password Generator Dialog
Account and securityA sign-up page with a dialog shown open that suggests a password: a mono output with Copy and a new one, Random or Passphrase, a length slider, four character switches and a strength worked out in bits.
- Pro
Centered Sign In Login
Centered formA full-height sign-in page for a team chat app: the product's mark, Google and GitHub rows with lettermark tiles, an or rule, email and password checked on submit, and one Sign in button with a simulated wait and its result.
- Pro
Deactivate 2FA Dialog
Destructive confirmsA security page with its turn-off confirmation shown open: an alert dialog that lists what goes with two-step verification, asks for the password and a ticked acknowledgement, and keeps its destructive action quiet until both are done.
- Pro
Two-Step Setup Dialog
Account and securityA cloud editor's security page with a three-step dialog shown open: a QR code and its key, eight backup codes to copy or download, and a six-digit check, ending in a note that two-step sign-in is on.