Lesson 8.3: Two-step sign-in
With two-step sign-in, a password alone no longer signs anyone in: after the password comes a code from an authenticator app or from an e-mail. A stolen or guessed password is then useless on its own. This lesson shows administrators how to turn it on, how users set it up, and what to do when a user loses their phone.
Note
Never enroll a real administrator account while trying it out. Use a test user with an address at
example.invalid, and keep the training installation's mail transport on file.
At a glance
| Course | Site administration |
| Module | Module 8: Security |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Intermediate |
| Audience | Site administrators |
| Prerequisites | Lesson 8.2; an administrator account, a test user and a shell; an authenticator app on a phone (optional) |
Learning objectives
After this lesson, learners can:
- explain what the second step protects against and what it does not;
- turn on two-step sign-in: the extension, the login handler, the user class field and the two policies;
- set up an authenticator app or e-mail codes for a test user and sign in with a code;
- reset the second step for a user who lost their phone;
- choose between opt-in and
Enforce2FA=enabled.
Trainer's notes
How to present it
Source: Two-step sign-in. The extension's own documentation is in
extension/sevenx_authentication_2fa/README.md and INSTALL.md.
- What a user sees (4 minutes). Sign in as always; a page asks for the 6-digit code; each code works once;
after five wrong codes the sign-in ends. Setup is under My account > Two-step sign-in (
/user2fa/setup). Changing or turning it off asks for a current code. - Turning it on (5 minutes). Four parts: the extension
sevenx_authentication_2faactive; the login handlersevenxUser2fabeforestandardin[UserSettings] LoginHandler[]; a field of the datatype 7x 2FA Configuration in the user class; and the policiesuser2fa/setupanduser2fa/verifyfor every role that signs in. Recommended: aSecretKeythat encrypts the authenticator secrets. - Opt-in or required (2 minutes).
[General] Enforce2FA=disabled(default) lets users opt in.enabledwithDefaultMethod=totpmakes a user without a second step set up the app right after the password. Enroll the administrators first. - Lost phone (2 minutes). An administrator opens the user's object, sets the Two-step sign-in field to E-mail one-time code or Disabled, and publishes.
- What protects it (2 minutes). A new session id after the code; codes limited per sign-in; e-mail codes kept
hashed; every step written to
var/log/auth.log, never a code or a secret.
Common questions
Does the extension come with a new installation? The guide says the installers activate it. Check Setup > Extensions on your training installation before class; the user class field and the login handler may still need to be set.
What if the encryption key is lost? Everyone sets the app up again. Keep SecretKey out of version control and in
the backup (Module 9).
Does social login skip the second step? No. A user found through a provider still passes their own second step.
Pitfalls
- Clock skew. Authenticator codes are only valid within about a minute. A training machine with a wrong clock refuses every code.
- No field in the user class. Users of a class without the field cannot keep a second step; the setup page says so.
settings/overrideoutranks a siteaccess. Mail sent from a test siteaccess still uses the global transport.
Hands-on exercise
Use your own training installation. If the trainer has already prepared steps 1 to 4, start at step 5.
Open Setup > Extensions and check that
sevenx_authentication_2fais active. If not, activate it as your trainer shows.In
settings/override/site.ini.append.php, set the login handlers (edit the file; keep a copy first):[UserSettings] LoginHandler[] LoginHandler[]=sevenxUser2fa LoginHandler[]=standardOpen the user class (Setup > Classes, group Users, class User) and check for a field of the datatype 7x 2FA Configuration. If there is none, add one with the identifier
two_factorand store the class.Open Users > Roles and policies, open the role of your test user (for example Member or Editor) and add the policies
user2fa/setupanduser2fa/verify.Clear the caches:
php bin/php/ezcache.php --clear-tag=iniand, if the site runs on Velocity,php bin/php/console exp:velocity deployas your trainer shows.In a private window, sign in as the test user and open
/user2fa/setup.Choose Authenticator app, scan the QR code with an app on your phone, and enter the code it shows. Without a phone, choose e-mail codes instead.
Sign out and sign in again. Enter the code from the app, or, for e-mail codes, find the newest file in
var/log/mailand read the code in it.Sign out, sign in, and type a wrong code twice before the right one.
As administrator, open Setup > Log files and read the newest lines of
auth.log.Reset the test user: open the user's object, set the Two-step sign-in field to Disabled and publish.
Expected result
- Step 7 ends with the second step active for the test user; the key is not shown again.
- Step 8: the sign-in asks for the code after the password, and the user is signed in only after the right code.
- Step 10 lists the steps of the sign-ins, including the wrong codes, and no code or secret.
- After step 11 the test user signs in with the password alone.
- The trainer checks one learner's
auth.logview on the projector.
Quiz
- Which two policies must every role that signs in hold?
- In which order must the login handlers be listed?
A.
standard, thensevenxUser2faB.sevenxUser2fa, thenstandardC. Order does not matter D. OnlysevenxUser2fa - A user lost their phone. What does the administrator do?
- What does
Enforce2FA=enabledwithDefaultMethod=totpdo for a user without a second step? - Which log records every step of two-step sign-in?
Answers
user2fa/setupanduser2fa/verify(Two-step sign-in).- B. The two-step handler comes before
standard. - Opens the user's object, sets the Two-step sign-in field to E-mail one-time code or Disabled, and publishes; the user then sets the app up again.
- The user must set up an authenticator app right after the password, before being signed in.
var/log/auth.log, without codes or secrets.
Further reading
- Two-step sign-in: users, administrators and what protects it.
- Security and audit, section 5: the short walk-through.
- Two-factor sign-in for hosts.
Related pages
- Module 8: Security
- Site administration: course overview
- Trainers: start here
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.