Sub topic 6
Registering multi-factor authentication
Multi-factor authentication (MFA) asks for a second proof of identity in addition to your password. Salesforce requires it for every direct login to the user interface, including a new Developer Edition org. This chapter covers what MFA protects, which verification methods Salesforce accepts, how to register two of them, and how to recover if you lose access.
This chapter assumes you have completed the previous chapter: you have a Developer Edition org, you have verified your email, and you have set a password. You also need a smartphone, a hardware security key, or a computer with a biometric unlock.
What MFA does and why Salesforce requires it
A password is something you know. MFA adds a second factor, such as something you have (a phone or a key) or something you are (a fingerprint or face). A stolen password alone then no longer lets someone in.
Salesforce enforces MFA for logins made with a username and password through the browser. This applies to your free org as well as to production orgs. If you skip registration, Salesforce keeps prompting you at login until you complete it.
MFA applies to the interactive login, not to every connection. A few consequences matter later in this tutorial:
- Logging in through the browser triggers MFA, and so does
sf org login web, because that command opens the same browser login page. - Once the CLI holds an authorization, it uses a stored token and does not ask for a second factor on each command.
- Single sign-on logins can satisfy MFA at the identity provider instead. A Developer Edition org normally uses Salesforce's own login, so this rarely applies to you.
Accepted verification methods
Salesforce accepts only methods that are hard to intercept. Email codes and text messages are not accepted as MFA verification methods.
| Method | What it is | Works offline | Notes |
|---|---|---|---|
| Salesforce Authenticator | Salesforce's mobile app. It sends a push notification you approve. | No, it needs a data connection | Also offers location-based automatic approval. |
| Third-party authenticator app | An app such as Google Authenticator, Microsoft Authenticator or Authy. It shows a six-digit code that changes every 30 seconds. | Yes | Uses the time-based one-time password (TOTP) standard. |
| Security key | A physical device such as a YubiKey. It uses the WebAuthn or U2F standard. | Yes | You touch the key to approve. |
| Built-in authenticator | Touch ID, Face ID or Windows Hello on your own computer or phone. | Yes | Tied to that one device. |
For a learning org, a TOTP app is a good default. It is free and works without a network connection to the phone. It also uses an open standard, so the same app can protect many other accounts.
Registering your first method
The first time you log in after setting a password, Salesforce shows a screen asking you to verify your identity. Follow the prompts, which look like this for an authenticator app:
- Choose the verification method (for example, a third-party authenticator app).
- Salesforce displays a QR code and a text key (the secret).
- Open your authenticator app, choose to add an account, and scan the QR code. If you cannot scan it, type the text key into the app by hand.
- The app now shows a six-digit code for the account. Type it into the Salesforce page and confirm.
Salesforce checks the code against its own calculation. If it matches, the method is registered and you are logged in.
How the six-digit code works
An authenticator app and Salesforce share one secret, the key encoded in the QR code. Both sides compute the code from that secret and the current time, so no message travels between the app and Salesforce when you log in. The following Python program implements the standard algorithm (RFC 6238) using only the standard library. It lets you see that the code is plain arithmetic and not magic.
import base64
import hashlib
import hmac
import struct
import time
def totp(secret_b32, step=30, digits=6, at=None):
"""Return the time-based one-time password for a base32 secret."""
key = base64.b32decode(secret_b32.replace(" ", "").upper())
moment = time.time() if at is None else at
counter = int(moment // step)
digest = hmac.new(key, struct.pack(">Q", counter), hashlib.sha1).digest()
offset = digest[-1] & 0x0F
number = struct.unpack(">I", digest[offset:offset + 4])[0] & 0x7FFFFFFF
return str(number % 10 ** digits).zfill(digits)
if __name__ == "__main__":
# Test vector from RFC 6238: the secret is the ASCII text "12345678901234567890".
secret = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
print(totp(secret, digits=8, at=59)) # prints 94287082
print(totp(secret)) # prints the code for the current timeThe first line printed must be 94287082, which is the value published in the RFC. The second line changes every 30 seconds.
This explains the most common MFA failure. If your phone's clock is wrong by more than about a minute, the app computes a different counter, and Salesforce rejects every code. Turn on automatic date and time on the device before you assume anything else is broken.
Registering a second method
You are the only administrator of your Developer Edition org. If you lose your only verification method, nobody inside the org can reset it for you. Register a backup before you do anything else.
To add or review methods later:
- Log in and open your profile picture menu, then choose Settings.
- Open Advanced User Details.
- Find the App Registration entries for the one-time password authenticator, the Salesforce Authenticator and the security key.
- Choose Connect, Add or Register for the method you want, and follow the prompts.
The exact label varies a little between releases, so search the page for "Registration" if you do not see the section at first.
Good pairings for a personal org:
- A TOTP app on your phone plus a hardware security key kept in a drawer.
- A TOTP app on your phone plus the built-in authenticator on your laptop.
- A TOTP app registered in two places, such as a phone and a password manager that supports TOTP. Check that you trust the password manager before you do this, because you then keep your password and second factor together.
Everyday behavior at login
After MFA is registered, each browser login follows the same sequence:
- Enter your username and password.
- Salesforce asks for your second factor.
- You enter the code, approve the push or touch the key.
The verification page may offer a "Don't ask again" option for that browser. Use it only on a computer you own. On a shared or public machine, leave it unchecked.
Salesforce may also ask for MFA again during a session before a sensitive action, which is called step-up authentication. This is normal and uses the same methods you have already registered.
Recovering when you lose a method
Which recovery path you have depends on what you still hold. Work down this list.
- You still have a second registered method. Log in with it, open Advanced User Details, remove the lost method, and register a replacement.
- You have a temporary verification code. In orgs with another administrator, that person can generate a temporary code for your user (in Setup, on the user's record). The code expires, by default after one hour. It gets you in so you can register a new method. A one-user Developer Edition org usually has no second administrator.
- You have saved the TOTP secret. Add it to a new authenticator app, and the app produces valid codes again.
- You have nothing. You need Salesforce Support, who will verify your identity before they help. Developer Edition orgs have limited support, so this can be slow. If the org holds nothing you need, creating a new Developer Edition org with a different username is often faster.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Code is always rejected | Phone clock is out of sync | Enable automatic date and time, then retry with a fresh code |
| Code was correct, but rejected | It expired while you typed it | Wait for the next code and type it promptly |
| QR code will not scan | Camera permission is denied, or the screen is too small | Enter the text key manually in the app |
| Push notification never arrives | Salesforce Authenticator has no data connection, or notifications are disabled | Check mobile data and notification settings, or use a TOTP code instead |
| Security key is not recognized | Browser or USB support problem | Try another USB port, or use Chrome, Edge or Firefox with the latest update |
| Login keeps asking you to register | You closed the registration before confirming a code | Log in again and complete the confirmation step |
MFA and the Salesforce CLI
The chapter on connecting the CLI comes later, but you can plan for MFA now. The command sf org login web --alias my-dev-org opens your browser, you log in normally, and you complete MFA as usual. The CLI stores an authorization afterwards. If MFA is not registered, the browser flow cannot finish. Register your methods first.
Exercise
You register a third-party authenticator app, and the very first code you enter is rejected. The QR code scanned correctly and the app shows a new code every 30 seconds. What is the most likely cause, and what do you check first?
Show answer
The most likely cause is a wrong clock on the phone. Both sides compute the code from the shared secret and the current 30-second time window, so a clock that is off by more than about a minute produces codes Salesforce does not expect. Turn on automatic date and time (network time) on the phone and enter the next code that appears.
Exercise
Why should you register a second verification method in a Developer Edition org that has only one user, and which two methods make a sensible pair?
Show answer
You are the only administrator, so nobody else can generate a temporary verification code for you if you lose your only method. Recovery would then depend on Salesforce Support. A sensible pair is a TOTP authenticator app on your phone plus a hardware security key (or the built-in authenticator on your laptop), because the two do not depend on the same device.
Exercise
Which of these can you use as an MFA verification method in Salesforce: a code sent by email, a code sent by text message, a TOTP authenticator app, a security key?
Show answer
The TOTP authenticator app and the security key. Email and text message codes are not accepted as MFA verification methods.