From what I understand, Time-based One Time Passwords used a seed and a mathematical algorithm to generate unique passwords. As the seed is known by the user (or the device used by the user), and the authentication server. However, this means that if the database is leaked, the seed will be known by the attacker.

As with a database leak, an attacker can know both the password and the OTP, does Time-based One Time Password improves security in case of database leak? Or is the goal of OTP only to prevent an attacker to authenticate when he knows the password by another way (another database leak, social engineering...)?

  • You may want answers focused on the scenario where both the password hashes and OTP seeds are leaked, but I thought I'd point out that the OTP seeds are often not stored in the same database as the hashes. They probably will be in a different database on a dedicated authentication server or even hosted by a third party authentication service. So the compromise of your password hashes doesn't necessitate a compromise of your OTP authentication in the real world. – PwdRsch Apr 25 '18 at 16:19

Actually, password is what is supposed to protect the user in case your database leaks. If you hash and salt properly, the attacker should not be able to obtain plaintext version of the password (with reasonable password in reasonable time with reasonable resources, if an attacker such as the NSA is after you, don't rely on this. Also, if you know your database leaked or could have leaked, force users to change password to be sure). Your app should not accept the hash as a valid password. So the attacker should not be able to log in even if database is leaked. Note: If you want to hash on client side, check schemes such as SCRAM-SHA256 to protect form this kind of attack.

TOTP on the other hand protects from user password being leaked by the user, or otherwise obtained (brute-force, interception, keylogger) without compromising server.

If you want additional protection in case server is compromised AND password is obtained (for example attacker intercepts login requests and get the password that way), consider either using something like SCRAM to limit the password exposure to the server, or using public-private key pair for login, possibly with hardware token using U2F.

  • 1
    With the right gear, even a strong hash will eventually be broken. The important part is to use hashing schemes that require an attacker to brute-force each password on an individual basis (random salts), and make it take as long as possible to do so (many iterations with a computationally expensive algorithm). For an individual user, it might be practical for an attacker to brute-force a password from the hash, but the whole database wouldn't be worth the effort. – nbering Apr 25 '18 at 14:15
  • 2
    @nbering Well, I took that as given when saying properly hashing and salting. While it is theoretically possible to still obtain single users password, there are very few if any practical situations, where that would be worth it to the attacker. But nice comment anyway. – Peter Harmann Apr 25 '18 at 14:18
  • 1
    I agree with the answer, I just wanted to add a point for context. Since the hashing is what protects the password, it needs to be taken seriously. Setting up 2fa but using unsalted md5 is not going to protect a user's account in the event of a database breach. – nbering Apr 25 '18 at 14:22
  • Please don't perpetuate the myth that hashing and salting properly will completely protect passwords. That does slow the attacker down, but it doesn't create the barrier against cracking you seem to think it does. – PwdRsch Apr 25 '18 at 15:53
  • 1
    @PeterHarmann I know this website, and also the XKCD comics. I think we agree on what's a good password, the only think i meant to say is that a password hash can be broken, even with "standard good practices" and a good enough hardware – Kepotx Apr 26 '18 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.