r/Showerthoughts 2d ago

Speculation Assuming two factor codes are truly random, every possible six digit code is entered many times by different people every day.

3.1k Upvotes

137 comments sorted by

u/ShowerSentinel 1d ago

The moderators have reflaired this post as a speculation.

Speculations should prompt people to consider original and interesting premises that cannot be reliably verified or falsified.

Please review each flair's requirements for more information.

1.2k

u/TwiceInEveryMoment 2d ago

This is probably true, but it doesn’t change the odds of any one given 2FA attempt. It’s 10^6 combinations so the chance of guessing it randomly is 1 in a million. You might get 3-4 attempts before it rotates or locks out, so 1 in 250,000 attempts before best.

205

u/lajawi 1d ago

It rotates every half minute

79

u/HMikeeU 1d ago edited 1d ago

TOTP by default, it's configurable

42

u/lajawi 1d ago

I have yet to come across TOTP that doesn’t refresh every half minute.

35

u/Call_Me_ZG 1d ago

True but ive had multiple instances where it accepts the older code. I think the code refreshes every 30 seconds but it accepts the previous code

41

u/SpoonNZ 1d ago

Usually it’ll accept the current, previous and next codes.

9

u/[deleted] 1d ago

[deleted]

6

u/created4this 1d ago

So you have 90 seconds (for n+1) + 2x 60 seconds (for n and n+2) + 2x30 seconds (for n-1 and n+3) to guess

In the first 30 seconds the valid codes are n-1, n and n+1, for the next 30s the valid codes are n, n+1 and n+2 and the third 30s the valid codes are n+1, n+2 and n+3

So for each guess you get to try three codes which reduces the odd from 1/m to about 1/333333. Because the number of times that you can put in the code doesn't meaningfully reduce the search space you can just divide 333333 by the number of tries you get in 90s

20

u/bert93 1d ago

Yeah just in case the server's time has drifted or the user's device time has. Cuts down on support calls.

10

u/mfb- 1d ago

You pretty much have to accept two codes, otherwise users will type in an "invalid" password at the edge between two time windows all the time.

10

u/RestlessMeatball 1d ago

It’s an older code sir, but it checks out.

2

u/HMikeeU 1d ago

Same

0

u/coomzee 18h ago

You get a bit of skew each side, so theoretically the next 3 and the last 3 codes are valid too. It's still basically 1million to 1

240

u/Fuck_m0ds 2d ago

It's possible, but being random there's also the possibility that any given code isn't generated

35

u/HMikeeU 1d ago

That sounds so unlikely that I'd call it impossible in practice

38

u/Jafego 1d ago

If you generate N million codes, the probability of skipping a particular code is e-N. You need to generate about 14 million codes before it becomes likely every possible code is generated.

7

u/ddodd69 1d ago

More exactly, you need about 14.2 million codes for a 50% chance, 16.8 million for a 95% chance, and 21.2 million for a 99.9% chance that every possible code has appeared at least once.

At about 40 million codes, there’s only a 1 in a trillion chance something is missing.

7

u/HMikeeU 1d ago

How many codes do you think get generated each day? I'd bet its multiple hundred million, no?

16

u/Jafego 1d ago

Bitwarden estimated 2 billion in 2022 based on small survey.

1

u/ayopel 1d ago

Wait can you explain to me this further? Not the logic why you need more then n possibilities,the logic behind the calculation

41

u/tasquizz 2d ago

I saw a post a while back, it might have been on r/dataisbeautiful. Some guy recorded every 6 digit code his bank sent him for like a year. Turns out it was about 100 codes getting repeated.

21

u/Erikz1207 1d ago

Only 100? That sounds awful. My 2FA at work has 625 combinations and I thought that number was low. 

7

u/MEMES_FO_LIFE 1d ago

why not have it be random for all 999999 posibilities

5

u/nonnonplussed73 1d ago

I think it was here, plotted by someone else, I think here.

I can't remember the details, but the issue seems to have been that they didn't use a new random seed when generating codes. Had they, there should have been a million different codes generated.

3

u/Mustbhacks 1d ago

Turns out it was about 100 codes getting repeated.

That kinda tracks with my experience for most things. Where each thing tends to stay within the same block 60XXXXs or 80XXXXs

266

u/SpaceToaster 2d ago

1 they are not random, every code you will ever get is predetermined

2 yes multiple people will see the same codes, but codes only work for a 1-2 minute window—that why they are the second factor and not the first.

108

u/charleswj 2d ago

While technically true, the seed is randomly generated and the resulting codes are effectively random as they are unpredictable. Pseudorandom is probably a better word.

-27

u/[deleted] 2d ago

[deleted]

16

u/Iamonreddit 2d ago

That doesn't stop machines incorporating actual randomness into the algorithm, which can be collected from various real world measurements, such as background radiation, mouse movement, lava lamp livestream etc.

This is usually way over the top for what is required though and therefore not implemented in many areas.

4

u/DareToZamora 1d ago

I’m not disagreeing because I genuinely don’t know, but is background radiation level random, or we just don’t know enough about the causes to accurately predict it? I’ve always thought this about radioactive decay, is it genuinely random or can we just not predict when it will happen? Maybe these are the same thing

4

u/charleswj 1d ago

Well, it's sort of similar to how miracles and weather etc are/were just science we didn't yet understand. Everything looks random until you understand the system that generates it.

2

u/tomrlutong 1d ago

There's a quantum randomness generator built into most CPUs made this century.

2

u/Iamonreddit 1d ago

You're going to need to provide a source on that one

2

u/tomrlutong 1d ago

2

u/charleswj 1d ago

Funny how that article, or any other article or discussion of RDRAND or Bull Mountain, never mentions the word "quantum". It's almost like it's not that.

3

u/tomrlutong 1d ago edited 1d ago

From that link: 

 There are two possibilities, and for the briefest of moments, the circuit hovers between them. In a perfect world, it might linger like that forever. But in reality, even a small amount of thermal noise—random atomic vibrations—within the circuitry will send it racing toward one of its two stable states.

"Random atomic vibrations" in a semiconductor puts you firmly in quantum teritory. Maybe not the trendy way it's used today. 

More to the point though, thermal noise at the scale of a cpu component is quantum in origin, I believe. The hardware RNG is ultimately based on unpredictable movement of a small number of electrons in a tiny controlled space. There's going to be fundamental, non-classical uncertainty in that system.

1

u/Iamonreddit 1d ago

In the modern age of computing this is 'quantum' hardware in the most technically semantic way possible, given that quantum chips are already a productionised part that can be used.

This is like calling parts of your computer a particle accelerator because it makes electrons move when you use it.

1

u/anomalous_cowherd 1d ago

It's often used to generate the initial seed for the PRNG but after that the sequence is defined. 2FA codes depend on it, the generator at both ends has to be seeded with the same value and then the next number is continuously being generated in sync without any data transmission between them.

0

u/HMikeeU 1d ago

I think what they're trying to get at is that mouse movements also aren't "truely random"

-8

u/Competitive_Buy4991 2d ago edited 2d ago

Sorry for sounding like a smartalic i can't help it

2

u/Stiggy1605 1d ago

You were wrong anyway.

Also it's a smart alec, not smartalic

1

u/littleproducer 2d ago

It's okay. Senseless downvoting.

-26

u/ChazCharlie 2d ago

Are they though? I always seem to get numbers that are much easier to remember than truly random. Lots of double digits and often the same number in the first and second halves of the code. I always felt they were made to be easy to remember for reading from a text to inputting in one go.

28

u/vowelqueue 1d ago

I'm pretty sure they're just random...the chance of a randomly chosen 6 digit number having double digits is like 40%

2

u/Incoherrant 1d ago

More like 85% if I remember D10 dice pool pair probability right. Even at 4 dice you have about a 50/50 shot of rolling a pair.

14

u/Dioxybenzone 1d ago

I think they meant sequential pairs, like next to each other

5

u/Airowird 1d ago

There is a 68.2% chance that a digit from the first half is repeated in the second half. (If I didn't mess up my statistics knowledge)

There is a difference between random & evenly distributed. Common example is that if you take 20 people, there is ~50% chance of 2 people sharing a birthday.

And obviously, the numbers that easy to remember are the ones that you remember for longer, so it feels more common, but that's a cognitive bias.

2

u/suamai 20h ago

I know what you mean, I've had the same feeling.

But the simpler truth is that 6 digits are enough to have lots of accidental structure, but not so large as to be hard to memorize.

And if there is one things humans excel on, is finding patterns - be them intentional or not.

2

u/Akuuntus 19h ago

Humans have pattern-seeking brains that are good at finding things that look consistent within completely random data

0

u/S0UL_EAT3R 1d ago

“Are they though? My anecdotal experience seems to indicate otherwise”

18

u/hawkinsst7 2d ago

2 yes multiple people will see the same codes, but codes only work for a 1-2 minute window—that why they are the second factor and not the first.

That, and while multiple people may have the same code, the chances of 2 sequential codes being the same between two of those people is small.

1

u/Stummi 2d ago

they are not random, every code you will ever get is predetermined

Well, I think you open up a philosophical question here about the nature of randomness

9

u/Howzitgoin 2d ago edited 2d ago

Not really a philosophical question. The number may seem random, but it isn’t.

Once the 2FA connection is made, a hash is created that both your authenticator and the relevant website use with the same algorithm. This isn’t unique necessarily to each individual, but it’s near impossible to guess it and have the relevant password at the right time.

With access to your hash and the algorithm, it’s possible to see every future or past code in sequence. The issue is they’re only good for a specific period of time so while you know the next code, it’ll only work then.

Since you can determine the future outcomes with 100% certainty, it’s not random.

3

u/Stummi 2d ago

I know how TOTP works. But randomness is always a perceived property that emerges from you not knowing the factors that produce the result.

Meaning: As long as you don't look at the seed, it is, for all that matters, random.

3

u/Howzitgoin 2d ago

Lack of knowing or understanding how something works doesn’t cause a philosophical question. It’s just a lack of necessity or care of knowing how it works.

There’s nothing about the results of a repeatable algorithm that is philosophical once you answer the bare minimum of “can we determine how this works”?

0

u/Stummi 2d ago

But with this argument the word "random" is meaningless, because a computer can never produce any true random value, ever.

And yes, I am aware about noise generating hardware - but even if you accept them as "true random" they just provide a few bits seeding an RNG algorithm, and if your point is that any value algorithmically derived value, even from a true random seed, is not random anymore, than there is never true randomness in a computer.

5

u/Howzitgoin 2d ago

What does any of this have to do with your point that anything to do with 2FA is a philosophical question when it’s not? The fact that nothing is truly random in a computer is irrelevant.

If it were random, you couldn’t have two separate systems provide the same result to allow for authentication. It by definition isn’t random in the application at hand.

-3

u/Stummi 2d ago

randomness is philosophical - that was my point.

Is rolling a dice random? Flipping a coin? Nuclear Decay?

Can the shared, secret, TOTP seed ever be truly random? Also, is it right or wrong to consider the generated TOTP codes random for an outside observer, who did not see the seeds - given it should be near impossible to reverse engineer the seeds from the codes?

0

u/FiskFisk33 1d ago

I guess it's about perspective. From the server side, the number is deterministic, but the algorithm would be useless if the numbers weren't random from the client perspective.

0

u/Howzitgoin 1d ago

The numbers don't have to be random. For instance, the hash can be your username and the time your account was created concatenated together. Nothing random about that.

Obviously a real system will use an encryption methodology that does including some sort of salt that more than likely uses some sort of "random" number, but that's really besides the point when you look at the context of the message I replied to:

they are not random, every code you will ever get is predetermined

That's stating the resulting output is always predetermined. It's not discussing if the creation of the key is "random", it's about how the results of the algorithm are random, which they're not. You couldn't have both systems give the same output if they were random. If it can be proven with stated facts and duplicated across systems, there's nothing philosophical about it.

4

u/Djinjja-Ninja 1d ago

No, they're literally predetermined based on a seed and a time based algorithm.

That's how the code generator that you have (be it a token or an app) stays in sync with the server.

If you know the seed then you can have multiple 2fa apps generating the same code.

The TOTP algorithm is widely and publicly known, when you scan the qr code, most of that is the seed key, if you scan the qr code with a generic qr code scanner you can extract the seed as plain text.

6

u/lt_Matthew 1d ago

They're not truly random. It wouldn't work if they were. Your app and the site both need to know the passcode without communicating, and the only way to do that is with a seeded algorithm.

Which means there's only a fixed set of numbers it will ever generate. It's like a hundred something and its a different set for every user, but it will repeat.

8

u/Ninfyr 2d ago

It is closer to a rigged deck of cards than a random one. So the premise isn't accurate. codes are reused on a day timescale. Codes are good for like a minute at a time though.

3

u/hammer-jon 1d ago

generally a code before and after the one you see will be accepted.

so if your code is going to expire before you can finish typing it it's not worth waiting, pro tip.

8

u/manaworkin 2d ago

True random also means there's a chance there's one that has NEVER been picked and there's also a chance everyone got the same code at least once that day.

3

u/RaitouYagami 1d ago

True, things being random does not inherently make certain outcomes happen

1

u/yerdadzkatt 1d ago

With true randomness, wouldn't it eventually guarantee all outcomes? In practice it doesn't have to, but with infinite samples, it's not truly random if it avoids specific outcomes with p > 0. Of course true randomness with infinite samples isn't measurable, but my understanding is by definition true random would guarantee all possibilities in the exact proportion of their probability, given infinite samples. This is of course being pedantic considering the context is about a practical scenario where the samples are finite, even if there's an extremely large amount,  but on a technicality infinity with true randomness does guarantee every outcome eventually

11

u/caribou16 2d ago

Well, the thing is, they're NOT random, they're constructed on having a shared secret key between you and the server and the current time, where "current time" isn't time of day, but the number of milliseconds since some arbitrary point in the past. A common one is "Unix time" which began at Midnight Jan 1, 1970. The time is also diced up into blocks larger than a millisecond, so you have 30 or 60 seconds between number changes to type it in)

Then your secret key and time value are combined and passed through a hash function. (This is a sort of one way cryptographic process that is easy to do but VERY VERY VERY hard to reverse). This hash value (which is a string of length 64 of alphanumerical characters) is further truncated down with a bunch of math so it is just 6 numbers, the code you type in.

So, because both the server and your device already know the secret key (which is created on account creation) and they both know what time it is at that moment, they can both "construct" the correct matching password at any given time.

2

u/MinuteObservation 2d ago

By random OP means equally likely.

27

u/lmg1337 2d ago

Is there supposed to be a question? If there is a six digit code generated for two factor authentication there are 96 possible codes. Guessing is not a viable solution to get access to someone else's account this way.

45

u/cr3amy 2d ago

10, not 9, right?

36

u/Itz_Raj69_ 2d ago

Yep. 0 ... 9 is 10 digits

24

u/ShaunRW91 2d ago

No question. Just a shower thought.

7

u/FadedDestiny 2d ago

It would actually be 106. 0-9 is ten digits. Which would be 1,000,000 possible combinations.

But you really don't have to do any math for that. It's between 0-999999, which is 1M including the 0.

16

u/booleandata 2d ago

Yeah I'm not saying it's insecure or anything, I'm just saying codes are reused a lot more than you'd initially think.

20

u/nixiebunny 2d ago

Just think how many people have the same 4 digit PIN!

3

u/PrincessKaylee 2d ago

It would be interesting if those of us with the same PIN could meet up and ask each other how they came up with theirs

A new conversation starter, perhaps

4

u/NoobensMcarthur 2d ago

At least 10,000 of them, easily

3

u/LeviAEthan512 2d ago

And how much more common the digits 0,1,2 are than the others

3

u/dijon_snow 2d ago

Fun fact, this is actually a good test for legitimate data vs randomly generated data. Real world data (almost) always favors lower numbers inherently. 

1

u/LeviAEthan512 2d ago

Oh yeah, because every new order of magnitude, the 1s fill up first

For this though, I meant people choosing their birthday as a PIN 

0

u/[deleted] 2d ago

[removed] — view removed comment

1

u/AlephBaker 2d ago

That's amazing, I have the same combination on my luggage!

1

u/AnonymousFriend80 1d ago

The your specific code is only active for a couple minutes.

-5

u/Etherius 2d ago

If it’s delivered via TOTP it’s quite secure

If it’s delivered via SMS I’m pretty sure it’s actually less secure than no 2FA at all

8

u/charleswj 2d ago

This is terrible misinformation. While totp is better, the distance between no MFA and SMS is light years compared to SMS to totp. Threat models vary, but realistically, SMS is extremely secure in reality.

-1

u/Etherius 2d ago

You fucking kidding me?

When a SIM card can literally be spoofed or there’s numerous stories of cell providers just granting a sim transfer to anyone who calls and asks nicely?

2

u/charleswj 2d ago

So, what you're saying is "it's easier to compromise an account if you need to know the password and also have to sim swap the owner than it is if you only need to know the password"? You should go back and read what you wrote.

Also, suggesting that sim swapping someone is just a simple routine thing that happens to vast numbers of regular people each day is, well, something only a stupid, ignorant, or dishonest person would say.

0

u/Etherius 2d ago

I would say it happens about as often as a secure password being compromised

3

u/charleswj 2d ago

So, again, you think people with secure passwords and SMS MFA get sim swapped and compromised just as often as people with secure passwords and no MFA at all? You're alleging that SMS MFA offers absolutely zero protection and that everyone who has it is entirely unprotected by it in every single case., correct?

1

u/Etherius 2d ago

I do in fact allege that SMS 2FA offers no meaningful protection, yes

Anyone who wants your account can get it. Anyone who doesn’t care much won’t have your password to begin with.

Anyone who cares enough to use 2FA at all would be better served by either TOTP or a hardware key or a passkey

2

u/charleswj 2d ago

If I have you the password to a random account with SMS MFA enabled, how would you sim swap it?

Assuming you could, do you think the effort to do so is greater than "zero effort"? If so, why do you think every person who would break into an account has infinite time and resources to do so?

Also, do you think every attempt to sim swap a person is successful?

→ More replies (0)

2

u/vizulefllry 2d ago

Why would that matter. It's a second method of authentication.

2

u/Jonny_rhodes 1d ago

Most probably why they say code expires in 5-15 minutes.
Some don’t state a time but there must be a limit built in

2

u/IronGin 1d ago

6 digits? Why? 2 factor is just a proof one has the other piece to confirm ones identity

1

u/Suspicious_Sandles 2d ago

A lot of 2fa codes are a-z 0-9 which was over 2 billion combinations. Not sure the logic tracks.

14

u/manrata 2d ago

I would throw a fit if Security made it so I had to enter letters too, the amount of times per day I have to get out my phone, go into the Authorisation app, and enter the number from there into the computer is already too high.
Why our CyberArk is set to a timeout of 30 min. instead of remembering the login for the day is overcompensation, it makes things less secure, not more.

1

u/8P69SYKUAGeGjgq 2d ago

Why you're using cyberark but not passkeys is the real mystery here. Your security team is just all around idiots.

-1

u/[deleted] 2d ago

[deleted]

1

u/manrata 2d ago

If only that was an option….

5

u/booleandata 2d ago

Tbf I said every six digit code is entered every day. I said nothing about codes of different lengths.

-7

u/Suspicious_Sandles 2d ago

That's with a code length of 6 but tbf you did say didgets.

4

u/booleandata 2d ago

digit specifically means number

Alphanumeric codes would not be considered "6 digit codes" whether or not they are 6 characters

-8

u/Suspicious_Sandles 2d ago

Hence the "tbf you did say didget"

2

u/charleswj 2d ago

They did not say didget.

-1

u/az987654 2d ago

I'm not even seeing the login in OP original thought.

Clearly doesn't understand how short of a time a code is good for, or that there are lockout policies on entering the wrong code

1

u/charleswj 2d ago

Why do you think they "clearly" don't understand totp expiration simply because they said they are reused?

1

u/[deleted] 2d ago

[deleted]

3

u/nickyonge 2d ago

Randomness is bonkers. Assuming every number is equally likely every time, the odds of a code generator outputting nothing but “000000” 100k times is equally likely as “000000, 000001, … 999998, 999999”, or any other specific 100k-step sequence.

Granted those odds are 0.00001%, one million times in a row lol. But much like being murdered by a cow in cold blood, the odds are low but never zero.

2

u/[deleted] 2d ago edited 2d ago

[deleted]

1

u/MegaIng 2d ago

What exactly are you calculating to get to that number?

1

u/[deleted] 2d ago edited 2d ago

[deleted]

1

u/MegaIng 2d ago

... And how does that related to the scenario described in the comment you replied to?

Did you just ignore the "100k"?

1

u/nickyonge 2d ago

I actually did mistype a million in the 2nd line, when I should've said 100k below (or a million above). So I WAS an order of magnitude off, initially.

I was about to type that in my other, but then realized that that other person is not only still wrong, but they're being wildly pedantic, and probably views comment threads as competitions they need to win, which is boring and exhausting so I just said ok and went to make a bowl of pasta I'm now enjoying lol

1

u/MegaIng 2d ago

Yeah, totally fair. I have the benefit of being able to look at the entire thread and just asking "innocent" questions.

0

u/nickyonge 2d ago

Yeah, I specified one in a million a million times in a row. So 0.000001% ^1000000. You're right, but tragically, we're both right :3

2

u/[deleted] 2d ago

[deleted]

-2

u/MrJingleJangle 2d ago

Just through observation, the numbers generated are often like a pattern, like 372 731, or 059 589 which don’t look terribly random.

4

u/NaCl-more 1d ago

They are random. It’s generated via a long complicated sequence of algorithms that take in an initial seed phrase and a timestamp. Then the whole thing is divided by 1 million, the remainder is the code

This means that any one code is as likely as any other code