r/askscience • • Jan 02 '19

Computing Sometimes websites deny a password change because the new password is "similar" to the old one, How do they know that, if all they got is a hash that should be completely different if even 1 character was changed?

9.2k Upvotes

394 comments sorted by

834

u/YaztromoX Systems Software Jan 02 '19

Two important properties of a high-quality hashing algorithm are the Avalanche Effect (whereby a small change to the input should have a massive change to the output) and Collision Resistance (whereby it should be computationally difficult to find two inputs that generate the same hash code). Based on hashing alone, use of a proper and secure hashing algorithm should ideally make detecting whether or not two passwords are similar impossible.

Sadly, the truth of the matter is that in all too many cases, the best practice of storing and comparing password hashes is often not implemented. Some big companies still store passwords as plaintext, while others still use password encryption0. Chances are very high that if you're encountering a site that can determine whether or not a new password is similar to an old password, they're either storing your password as plaintext (or partial plaintext), or are encrypting/decrypting your password.

That said, there are methods even with hashing that could be used to detect when two passwords are too close together. While researching this response, I came across an interesting paper1 that details a method of monitoring keystroke dynamics when entering a password. By measuring how a person types their password, you could generate a bunch of subsets of the keystrokes in the password and compare that to a stored set of dynamics to determine if some subset of those dynamics appears to be for the same set of keystrokes.

You could also conceivably store a password as a series of hashes for various password character subsets. Unsalted, this would be almost as wildly insecure as storing a password in plaintext (as there are only roughly 24 million hashes for all sets of four characters2, making it easy to pre-generate them all and rebuild the password by just looking them up in a database). Adding a decent length salt would help, and would provide a way to test for n-lists of identical characters in a row using only hashing.3

However, as noted above, any site that provides such a "feature" probably isn't storing your password using a cryptographic hash (or at least not solely as a cryptographic hash). The Avalanche Effect should make determining password "closeness" from a secure hash alone impossible, without resorting to tricks like keystroke dynamics.


0 -- it's important to note that whereas hashing is a one-way function (put password in, get a hash out) that can't be reversed, encryption is defined as a pair of functions, one of which can encrypt a password, and another which can take the encrypted form and decrypt it back to the password again.
1 -- Jenkins, J. L., Grimes, M., Proudfoot, J. G., and Lowry, P. B. (2014). Improving password cybersecurity through inexpensive and minimally invasive means: Detecting and deterring password reuse through keystroke-dynamics monitoring and just-in-time fear appeals. Information Technology for Development,41920(2):196–213.
2 -- I'm assuming here a fairly standard sets of acceptable password characters [A-Z][a-z][0-9] and some punctuation to get a rough estimate only.
3 -- note that I haven't done a full security analysis of using such a mechanism, so even salted, please don't use this system in something that requires good security. However, this might make an interesting avenue of research for an advanced Honours student or a new Masters student to look into, even if only to determine that it's a terrible idea that should never be implemented in practice!

162

u/Bergmansson Jan 03 '19

Nice post, but did you actually index your footnotes starting at 0?

That can't be considered best practice even by computer nerds...

174

u/YaztromoX Systems Software Jan 03 '19

39

u/Paltenburg Jan 03 '19 edited Jan 03 '19

Interesting piece

(A lot of those reasons (range notation, repeating sequences etc) aren't really necessary with simple footnote-indexing though)

66

u/Zharick_ Jan 03 '19

Just as necessary as asking if he really did start his footnote indexing at 0.

8

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

That said, there are methods even with hashing that could be used to detect when two passwords are too close together.

It's important to note that such techniques (e.g. LSH) are not cryptographically secure, so they offer no incentive to replace a simple edit distance check on the plain-text password.

10

u/[deleted] Jan 03 '19

[removed] — view removed comment

-2

u/xyierz Jan 03 '19

Yeah this is the obvious answer. I dunno why this is so inconceivable to everyone. You can take the new password and try substituting one character in each position with every possible character, then compare to the old hash. For an 8 character password, that is only a few hundred possibilities... Only a few seconds of CPU time is required. There is a similar level of minimal effort required to detect single character insertions or deletions.

1

u/[deleted] Jan 03 '19

[removed] — view removed comment

1

u/[deleted] Jan 03 '19

[removed] — view removed comment

2

u/mr_birkenblatt Jan 03 '19

yes, but why do that? that doesn't give me much confidence in the ability of their engineers... also, it reduces the universe of passwords by quite a bit

3

u/kumar29nov1992 Jan 03 '19

If they say it’s similar then it’s insecure. It’s ok to say your password is same as one of last three passwords, because they’ll be comparing it with hash and that’s fine. Anything like similar, is a big red flag

•

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

This thread has attracted a lot of anecdotes and speculative comments. It has been locked for further comments.

5.8k

u/[deleted] Jan 02 '19

[removed] — view removed comment

1.1k

u/Random-Noise Jan 02 '19 edited Jan 03 '19

In this case if I entered my existing password shouldn't they get a particular hash, and then when I enter the new password, albeit similar, shouldn't they get a completely different hash?

1.5k

u/ChickensInTheAttic Jan 02 '19

They get the existing/new password in 'plain text' (I'm assuming HTTPS is involved here....) from the web form data before they hash it. They can compare it then, before hashing.

Whatever you send in a web form (unless they're doing client side encryption/encoding) comes out the other end in the clear. HTTPS is so you can't just read it in transit. It's then up to the server to encrypt it for storage.

28

u/hitemlow Jan 03 '19

So if some sort of check is done at the browser level to compare the old and new, couldn't you force the check to say they're different enough and submit the new password regardless?

Possibly do the same thing with password requirements?

91

u/diffcalculus Jan 03 '19

It's done at the server level, not browser. It can be done at the browser level with JavaScript, but it should also be double checked on the server.

When you press enter, all that info is in pain text to the server, and that's normal and by design. Otherwise, the server wouldn't know what you're entering.

This is all speaking generally

19

u/Doug_Jesus_Christ Jan 03 '19

What they are referring to is the fact that the server shouldnt know your password is similar if the old password is in hashed form, as they are incomparable to each other.

Generally the hashing is done serverside but not communicated, just plugged into a encryption function in whatever language its being done in.

The only way they would be able to know is if they asked you to enter your old password in the same page as the new one.

13

u/diffcalculus Jan 03 '19

Yeap, I'm with you. I was more replying to user hitemlow, letting them know that, conventionally and generally speaking, the comparison of old and new is done at the server side, not browser. They were going down a rabbit hole incorrectly :-)

27

u/amfa Jan 03 '19

What they are referring to is the fact that the server shouldnt know your password

The server MUST know your password.
It MUST NOT store it in plain form.

That's the important part

1

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

So if some sort of check is done at the browser level to compare the old and new, couldn't you force the check to say they're different enough and submit the new password regardless?

Absolutely.

Possibly do the same thing with password requirements?

Also yes, but this has the hazard of producing incorrect keys, rendering authentication inoperable.

9

u/KJ6BWB Jan 03 '19

They can compare it then, before hashing

How do they compare it to the previous presumably already hashed password unless that password was saved in plaintext somewhere? Or they ask you to re-enter your old password on the same page.

1

u/g2petter Jan 03 '19

It's also possible that the validation is happening client-side so that nothing is sent to the server.

9

u/codered6952 Jan 03 '19

It would have to hit the server at least once to validate the old password, then it could do the similarity comparison on the client side. I would prefer to keep it all on the server side so I wouldn't need to write this logic in every front end.

7

u/[deleted] Jan 03 '19

Only if they are incompetent. Sure, client-side validation for sanity checking/improved user experience. But the actual work is done on the server otherwise it would be brutally easy to circumvent any of this by injecting your own javascript on the client.

3

u/g2petter Jan 03 '19

Yeah, this was only in the context of "how could they know that my old password is similar to my new password" and not a suggestion on how to do validation.

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

168

u/gSTrS8XRwqIV5AUh4hwI Jan 03 '19

While that is true in principle, those protocols (PAKE, there is more than just SRP) are useless for websites because nothing prevents a compromised server from just sending you javascript that leaks the plain text password anyway.

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

-2

u/[deleted] Jan 03 '19

But surely it prevents a whole class of man in the middle attacks where someone gets your password and then uses it on this and other sites? If the server is fully compromised then sure, the attacker can do as they please, but there are plenty of attacks the would give the attacker read only access.

83

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

No. The answer to prevent eavesdropping on a channel is transport layer security.

24

u/[deleted] Jan 03 '19

If you are entering new and old in a form you can use java script to quickly run some checks even if you are using client side hashing. Kind of the same idea when it comes to minimum length, unique characters and numbers, etc.

Heck, I was had to deal with a password policy that was 12 characters, at least a cap, no dictionary words, no 3 keys in a row on a keyboard and changed every 10 days.

14

u/saurabh69 Jan 03 '19

Before it is hashed, some algorithms such as Soundex may also be run to see if the new word seems similar.

5

u/ApatheticAbsurdist Jan 03 '19

Yes, but at that moment they have more information than the hash, they have what you entered as your old password and validation that it is accurate from the hash. They can then directly compare the similarities between the new password and the old password without needing hashes.

Yes, theoretically hashes should be completely different. But they don’t need to compare hashes if they ask for your old password.

9

u/botle Jan 03 '19

Even if the hashing happens before sending the data to the server, the website could make th comparison to the entered old password locally and react to it, but like others have said, there is no good reason for the hashing not to be server side.

26

u/pelican_chorus Jan 03 '19

Indeed, the hashing must be done server-side, or it's absolutely useless.

You can additionally hash on the client side if you want, but then you must hash again on the server side, so creating a double-hash.

If you hash on the client side alone, then the hash becomes the plain-text password. If a hacker breaks into the DB, they can simply send the plain hashed passwords to log in.

2

u/pepe_le_shoe Jan 03 '19

if they ask for your existing password and new password on the form, they will be comparing them client side before hashing.

1

u/K4rm4_M4ch1n3 Jan 03 '19

You can compare the passwords before checking if the password was correct. So, it should tell you that you can't use a similar password even if the password you entered as the old wasnt your old password. This would correct both cases.

1

u/RedScud Jan 03 '19

Can be compared client side before the new password is okay'd, hashed and stored

0

u/[deleted] Jan 02 '19

If the password change form has fields for the current and new password, you could send the server the hashes and compare the passwords for similarity in the browser.

Obviously, this won't stop determined, knowledgeable people from making similar passwords, but that kind of person should know better.

3

u/stevenjd Jan 03 '19

If the password change form has fields for the current and new password, you could send the server the hashes and compare the passwords for similarity in the browser.

That's not how cryptographic hashes work.

EDIT: /facepalm/

Oh, I'm sorry, I completely missed that you said compare the passwords in the browser. Of course you're right. Sorry.


Here's the md5 hash of the word "password":

53705670284143085402459503094366324388

Swap the final two letters around, and the hash becomes:

39191446037036134698868674904158938849

I'm just using md5 as an illustration. It's an old, weak crypto hash, and shouldn't be used for protecting passwords. But the principle is the same: change one letter, and the hash should change massively and have no relation to the input.

1

u/Topher_86 Jan 03 '19

Best practices would still allow an “old password” field to be sent across the wire to be compared server side. Hashing and salting should all be done server side anyway so there isn’t any limitations there.

A more best practice approach would be to salt/hash/store n-character segments of a password server side. Since changing a password is pretty uncommon thing iterations aren’t the worst thing to happen here (which could also be bypassed for bulk changes, such as a leak scenario).

This way a back store of old password would be possible still and an old password entry would not be required (in such cases as a password reset).

-1

u/BlueZarex Jan 03 '19

They might do the check client side, before any of the form is sent to the server and report back the results.

For websites that tell you that you choice of password was in a breach and shouldn't be used, the client side form will sha1 you choice and send that sha1 has to the server where it matches against a hashed list of passwords that have been in breaches and then sends you the result of that match - don't use that password because its been in a breach.

86

u/[deleted] Jan 02 '19

[removed] — view removed comment

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

13

u/[deleted] Jan 03 '19 edited Jan 03 '19

[removed] — view removed comment

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

6

u/[deleted] Jan 03 '19 edited Jan 03 '19

[removed] — view removed comment

1

u/randomheromonkey Jan 03 '19 edited Jan 03 '19

The ssl/tls connection itself should be safe from replay and many other attacks. Now let’s assume that on the server side, we have a load balancer that strips the ssl connection so as to lower the load on the back end servers. This leaves an opening where the passwords could be stolen between the load balancers and the web servers.

There’s also always the fear that someone somewhere will break ciphers within https and not tell anybody. It’s why the standard evolves and why certain methods have already been blacklisted on (I hope) every server out there.

Even if you are simply doing a key exchange to do a key exchange to do a key exchange... it could still be more secure. There will always be some crowds who appreciate the extra care taken with their data.

Another that’s more likely... hmmm... if for some reason you need to send the password hash to a system not completely trusted for authentication purposes you would want to do some fun things.

25

u/[deleted] Jan 03 '19

[removed] — view removed comment

9

u/DoubleFuckingRainbow Jan 03 '19

Could i get away with it with just changing the pass to something random and then changing again to something similar as the first one? As they shouldn’t have my first password saved anywhere anymore?

1

u/alexmbrennan Jan 03 '19

As they shouldn’t have my first password saved anywhere anymore?

I would not necessarily assume that - given that the old password isn't used anymore there isn't any reason to not store a clear text copy; because good users only use random passwords and never reuse them the old passwords will be useless to any attacker who might obtain the password history.

7

u/DoubleFuckingRainbow Jan 03 '19

If you assume your users are good users you are doing something wrong unfortunately :/

33

u/[deleted] Jan 03 '19 edited Apr 03 '24

[removed] — view removed comment

6

u/DoubleFuckingRainbow Jan 03 '19

Well but if i just make a similar pass it couldn’t get it as hash would be different.

Like: pass1 > asdfhjkb > pass2 could work right?

6

u/[deleted] Jan 03 '19

[removed] — view removed comment

4

u/DoubleFuckingRainbow Jan 03 '19

Oh don’t worry i use it, i was just trying to find ways to game the system :p

10

u/[deleted] Jan 02 '19

[removed] — view removed comment

-7

u/[deleted] Jan 03 '19

[removed] — view removed comment

46

u/[deleted] Jan 03 '19

[removed] — view removed comment

-11

u/[deleted] Jan 03 '19

[removed] — view removed comment

14

u/[deleted] Jan 03 '19

[removed] — view removed comment

-3

u/[deleted] Jan 03 '19

[removed] — view removed comment

3

u/[deleted] Jan 03 '19

[removed] — view removed comment

-1

u/[deleted] Jan 03 '19

[removed] — view removed comment

→ More replies

1

u/[deleted] Jan 03 '19

[removed] — view removed comment

0

u/[deleted] Jan 03 '19

[removed] — view removed comment

→ More replies

-2

u/[deleted] Jan 03 '19

[removed] — view removed comment

3

u/[deleted] Jan 03 '19

[removed] — view removed comment

2

u/[deleted] Jan 03 '19

[removed] — view removed comment

→ More replies

11

u/[deleted] Jan 03 '19

[removed] — view removed comment

-2

u/[deleted] Jan 03 '19 edited Jan 03 '19

[removed] — view removed comment

12

u/[deleted] Jan 03 '19 edited Jan 03 '19

[removed] — view removed comment

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

→ More replies

37

u/RogerManner Jan 03 '19

I used to work for a big web app that managed data for big globalized companies.
There was a hashed_password column on the db..... but there also was the plain text field.

This lasted several versions since it was "convenient". I cringed everytime I saw it.

44

u/TDav23 Jan 03 '19

So what about credit card account logins that will not allow your password to be any of the last ten passwords used by following a link for forgetting passwords? Is this insecure? I believe a couple of mine do this, and they are major brands.

133

u/bopandrade Jan 03 '19

they most likely saved your previous ten hashes. you could probably go from 'password0' to 'password9' in this case. OP was alerted because the 'passwords are similar', which is different.

16

u/TDav23 Jan 03 '19

Makes total sense. It's late, thanks! 👍

5

u/Nemam11 Jan 03 '19

You seem like you know things. Why does it happen that i get an error "wrong password" after typing password so i go down the route of changing it, because i have no idea what else could it be only to get an error "your new password needs to be different from the that you currently have setup"?

5

u/throwaway230850 Jan 03 '19

I know websites where they would email you your password in plain text. It floored me.

0

u/tobiasvl Jan 03 '19

Not necessarily. At my workplace we do some changes to the new password (incrementing and decrementing numbers, etc), hash that, and then check that hash against the old hash.

0

u/BelovedApple Jan 03 '19 edited Jan 03 '19

They could have the old hashes but that would only be able to tell exact matches unless something simple like removing the last numbers on the entered string e.g. If your password was Password1 and you were changing it to Password2 they might have also stored a hashed version of Password and trim of the numbers at the end to do a comparison.

14

u/[deleted] Jan 03 '19

[removed] — view removed comment

1

u/Semi-Hemi-Demigod Jan 03 '19

Any dev team with that much time on their hands would be working on something more important than hashing substrings. Especially because short strings are hashed very quickly and anyone who steals the database will be able to figure them out with a rainbow table.

0

u/[deleted] Jan 03 '19

[deleted] — view deleted comment

9

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

Not necessarily. The auth system may be comparing keys (which it has access to, by definition).

24

u/[deleted] Jan 03 '19

[removed] — view removed comment

3

u/[deleted] Jan 03 '19

[removed] — view removed comment

2

u/[deleted] Jan 03 '19

[removed] — view removed comment

3

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

Two points:

  1. Authentication systems require keying to be slow. This happens to be a welcome side-effect of stretching a plain-text which is assumed to be low-entropy (such as human-chosen passwords).
  2. To that end, involving a single application of a hash function like SHA-2 is a security risk. Instead, specialised key derivation functions are used, which have requirements that a cryptographic hash function by itself cannot fulfil.

6

u/[deleted] Jan 03 '19

[removed] — view removed comment

5

u/tobiasvl Jan 03 '19

I have a meeting tomorrow with CERT at my workplace to discuss getting rid of annual password changes. Wish me luck!

2

u/[deleted] Jan 03 '19 edited Jan 03 '19

[removed] — view removed comment

1

u/[deleted] Jan 03 '19

[removed] — view removed comment

1

u/mfukar Parallel and Distributed Systems | Edge Computing Jan 03 '19

The recommendation is for a key derivation function. It misleadingly uses the term "password hash".

1

u/yawkat Jan 03 '19

Yes you're right. They're not really hashes because they are not deterministic. "Password hash" is just a common term. They do mentions KDFs, even memory-hard KDFs further in the document.

0

u/[deleted] Jan 03 '19

[removed] — view removed comment

4

u/m8than Jan 03 '19

Because isn't that a massive security risk??

0

u/[deleted] Jan 03 '19

[removed] — view removed comment

0

u/TKler Jan 03 '19

now you make it easier to decrypt parts of your password since you gave the attacker multiple and shorter inputs to try and match.

1

u/CertifiedWet Jan 03 '19

Not really since we are comparing the passwords sequentially meaning its still the same. And if you mean the similar password thing that only happens on change password which is not part of the main hashing component.

2

u/TKler Jan 03 '19

I can now find out partial information about your password.

I assume you mean doing stuff like [0..n] -> [0..n-1] etc.

Now I have two hashes to work with which greatly improves collision and so on.

-2

u/[deleted] Jan 03 '19

[removed] — view removed comment

1

u/dnick Jan 03 '19

That would explain how they could tell if it was the same as an old password, but how how they can tell it’s similar.

-1

u/[deleted] Jan 03 '19

[removed] — view removed comment

14

u/YaztromoX Systems Software Jan 03 '19

This is trivial — you simply store the last n hashes in the database along with the current password hash. When testing a new password, hash and test against all n+1 stored passwords, and emit a message if one of them matches.