shadcn.io is not affiliated with official shadcn/ui
Two-Factor Authenticator Login Block for React
A split sign-in step for an investing app: a six-digit code field beside a demo authenticator whose code and draining ring change every 30 seconds, where the current code and the one before it both sign in.
Installation
Overview
Ask for the code from an authenticator app, and show what that app does, with this two-factor login block for React with Base UI. It's the second step of a Coppergrove sign-in, an investing app: the page's side rails run the full height and one band crosses the screen, split in two by a divider with a plus mark where it meets each rule. At the start, a six-digit Input OTP and one Verify button. At the end, a demo authenticator: a card with the current code in large figures, a Circular Progress ring that drains over the 30-second window, the code of the window before it, and a Pause button. The current code signs in, and so does the one before it, and the result says which window it came from. Any other code is refused in words. On phones the authenticator is hidden and the demo code is printed under the field instead. It's built from Input OTP, Circular Progress, Field, Button, Shine Button and Guides, with a CSS entrance only. For sign-ins that ask for a time-based code.
FAQ
Where do the codes come from, and what stays in the page?
From a typed list of eight, one per 30-second window, shown in turn and starting again at the end; nothing is calculated. The authenticator is a drawing of what a real app does, and the page sends and stores nothing. In a product the code is a time-based one-time password: your server and the person's app share a secret when two-factor is turned on, and both work out the same six digits from the secret and the clock.
Why does the previous code work too?
Clocks drift and people type slowly, so a code is usually accepted for a little after its window ends. The page accepts the current code and the one before it, shows that previous code on the card ("Previous code, still accepted") and says in the result which one was used. A real server should do the same, no more than a window or so, and refuse a code it has already accepted.
What does Pause do?
It stops the demo's clock, and so the code and the ring, until it is pressed again, so there is time to type without the code changing. It is a toggle button: its pressed state is exposed to assistive technology and it fills with the text color when on, and a polite message says the codes are paused or running. Everything else on the page keeps working while it is paused.
What happens with reduced motion?
This is the one block whose codes change on their own, so it has a visible way to stop them. With reduced motion the ring no longer animates; the digits still change every 30 seconds, and Pause is still there. Nothing else on the page loops.
What do phones show?
Below the large breakpoint the authenticator is hidden, since it is a drawing and the form should come first. The hint under the field then prints the current demo code and says it changes every 30 seconds; on wide screens the hint points to the authenticator instead, so the code is shown once.
Related
- Pro
OTP Verification Login
Codes and approvalsA code step for a parcel locker app: a six-digit field that checks itself on the sixth digit or on a paste, counts wrong codes down from three, and a resend button that waits 30 seconds after it is pressed.
- Pro
Push Approval Number Matching Login
Codes and approvalsAn approval step for a freight dashboard: choose Push, Text or Call, send the request and match the number on screen with two demo buttons that play the phone, with a 60-second timer, a wrong-number cancel and an expiry.
- Pro
Backup Code Login
Codes and approvalsA sign-in step that takes one of eight single-use backup codes: the field adds the dash as you type, a saved sheet strikes spent codes through, and signing in offers new codes behind an alert dialog.
- Pro
Verify Identity Code Delivery Login
Codes and approvalsA verification step that asks where the code should go (text message, email or authenticator app), swaps to the code field once it is sent, and counts a limit of three codes an hour down with every send.
- Pro
Two-Factor Methods Account
Sign-in methodsAn account's two-factor methods as rows with their role, history and a Test that opens a code field in place, Make primary, a guarded Remove, and a Set up that opens a QR code, a key name or a number.
- Pro
Device Approval Login
Codes and approvalsA sign-in screen with a drawn phone: it asks whether the request is you, shows three number buttons, approves the matching one, denies a wrong one and points Deny to a password change.