Multi-factor authentication (MFA) in Cybersecurity - Time & Space Complexity
We want to understand how the time needed to verify a user changes as more authentication steps are added in multi-factor authentication (MFA).
How does adding more factors affect the time it takes to complete login?
Analyze the time complexity of the following MFA verification process.
function verifyMFA(factors) {
for (let i = 0; i < factors.length; i++) {
if (!verifyFactor(factors[i])) {
return false;
}
}
return true;
}
function verifyFactor(factor) {
// Simulate verification step (e.g., password, code, biometric)
return true; // assume success for simplicity
}
This code checks each authentication factor one by one until all are verified or one fails.
- Primary operation: Loop through each authentication factor to verify it.
- How many times: Once for each factor in the list.
As the number of factors increases, the time to verify grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 2 | 2 verification steps |
| 3 | 3 verification steps |
| 5 | 5 verification steps |
Pattern observation: Each added factor adds one more verification step, so time grows linearly.
Time Complexity: O(n)
This means the time to complete MFA grows directly with the number of factors to check.
[X] Wrong: "Adding more factors does not affect login time much because they run in parallel."
[OK] Correct: Usually, MFA factors are checked one after another, so each adds time. They rarely run fully in parallel.
Understanding how verification steps add up helps you explain system delays and design efficient authentication flows.
What if we verified all factors at the same time instead of one by one? How would the time complexity change?