Sub topic 7
Securing the Account with Two-Factor Authentication
This chapter assumes you understand passwords, web accounts, and basic cryptocurrency exchange accounts. It focuses on securing a custodial account, where the exchange controls the wallet keys and can approve withdrawals for you.
Why two-factor authentication matters
Two-factor authentication (2FA) requires two different kinds of proof before an account action succeeds:
- Something you know, such as a password.
- Something you have, such as a phone, authenticator app, or security key.
A stolen password alone should not be enough to access the account. However, 2FA does not protect you from every attack. If you approve a fraudulent login or enter a code into a phishing site, an attacker may still take control.
Prefer these methods, in order:
- A hardware security key using WebAuthn or FIDO2.
- An authenticator app using time-based one-time passwords, or TOTP.
- SMS codes, only when stronger methods are unavailable.
SMS is weaker because criminals may trick a mobile carrier into moving your number to another SIM card. This attack is called SIM swapping.
Set up an authenticator app
Install an authenticator app from your phone's official app store. In the exchange's security settings, choose authenticator-app 2FA. The exchange will show a QR code and usually a recovery key.
Scan the QR code only inside the official app or website. Save the recovery key offline in a secure place. Do not store it in an email, screenshot folder, cloud note, or password-free document. Enter the current six-digit code to confirm setup, then save the exchange's backup codes if it provides them.
import base64
import hashlib
import hmac
import struct
import time
def totp(secret_b32, step=30, digits=6, at=None):
secret_b32 = secret_b32.replace(" ", "").upper()
secret_b32 += "=" * (-len(secret_b32) % 8)
key = base64.b32decode(secret_b32)
counter = int((time.time() if at is None else at) // step)
digest = hmac.new(key, struct.pack(">Q", counter), hashlib.sha1).digest()
offset = digest[-1] & 0x0F
value = struct.unpack(">I", digest[offset:offset + 4])[0] & 0x7FFFFFFF
return str(value % 10 ** digits).zfill(digits)
print(totp("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", at=59)) # 287082This example implements the TOTP calculation used by many authenticator apps. The shared secret is the key that both the exchange and app know. The changing code is based on that key and the current time. Never use a secret from a real exchange account in a test program.
Protect withdrawals and recovery
Use a unique password stored in a password manager. Enable withdrawal address allowlists and withdrawal delays when available. Add a security key for login and withdrawals if the exchange supports it.
Store backup codes offline and test that you can find them. If you lose your phone, use a backup code or the exchange's official recovery process. Do not disable 2FA permanently to solve a temporary login problem.
Exercise
Exercise
Why is an authenticator app generally safer than SMS 2FA, and what must you protect during setup?
Show answer
An authenticator app is not exposed to SIM swapping. Protect the shared recovery key and backup codes because either can help someone bypass the normal second factor.