Can Two Passwords Have The Same Hash? (Why?) – InfosecScout (2024)

As you may already know, most passwords are stored hashed by the developers of your favorites websites. It means they don’t keep the password you chose in a plain text form, they convert it into another value, a representation of this password. But in the process, can two passwords have the same hash representation? That’s what we’ll see in this article.

Two passwords can produce the same hash, it’s named a “hash collision”. In this case, both passwords can be used to log in to the corresponding account. It’s extremely rare for most hashing algorithms, but it may happen.

In the following of this article, we’ll take a step back and see why these cases can happen.

Master Ethical Hacking Skills!
Join the Complete Ethical Hacking Course Bundle and step into the world of cybersecurity.
Learn to think like a hacker and protect systems with this comprehensive course.

Table of Contents

Can Two Passwords Have The Same Hash? (Why?) – InfosecScout (1)

Master Linux Commands
Your essential Linux handbook
Want to level up your Linux skills? Here is the perfect solution to become efficient on Linux. 20% off today!

Download now

Can Two Passwords Share The Same Hash?

Hashing Algorithms Reminders

A hashing algorithm is a one-way cryptographic function, that convert any text input to a representation of it. There is no reverse function (to get the text back from the representation), that’s why it’s often used to store passwords in a database.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

Many algorithms have been created over the years, but basically, they all work the same way for the end-user (generally a developer). They convert a string to a fixed size representation of it.

For example, MD5 was a popular hashing algorithm, that convert something like “infosecscout” into a string like “0fa6a5d3d5b1372077300af64ab8565e“. You can use MD5 functions in your code, or MD5 online tools to try this.

Hashing Functions Examples

Let’s take an example, if you need something more visual to understand the issue here (or the non-issue).
Let’s say your password is “azerty123”, which is a terrible password, but it doesn’t matter for this example. In theory, no website or app will store your password as it is, they will generally “convert” it to a hash representation, using any hash function they think are safe enough to do this.

Here is what this representation looks like with popular algorithms:

  • MD5: 882baf28143fb700b388a87ef561a6e5
  • SHA-1: 3b004ac6d8a602681f5ee3587c924855679e21d9
  • SHA-256: f3029a66c61b61b41b428963a2fc134154a5383096c776f3b4064733c5463d90
  • Bcrypt: $2a$10$XyoOPNRz27wsM9innHTSP.d3.ldFy8hgxLDfb3GVGPu.XS5R6Sfoa

Each algorithm use different characters set and length to hash your password, but basically, they work the same way.

Why Two Passwords Can Have The Same Hash

Two passwords can have the same hash if there is a collision. For example, the MD5 algorithm take any string, from any length, and convert it into a 32 hexadecimal characters string. As the list of possibilities is way bigger on the input side than on the output, there is no way you will never get the same output twice for two different input strings.

Can Two Passwords Have The Same Hash? (Why?) – InfosecScout (2)

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

The more possibilities you have on the output, the less often the issue will happen.
For example, SHA-1 use 40 characters instead of 32 for MD5, so there is a bit less duplicates with this algorithm.

How Likely Is Hash Collision?

As a whole, hash collisions are very rare. Even for broken algorithms like MD5, the probability to have two passwords producing the same hash is terribly low (1.47*10-29 according to Avira).

Hide your IP address and location with a free VPN:
Try it for free now, with advanced security features.
2900+ servers in 65 countries. It's free. Forever.

This eventuality might be a concern when you are hashing really long input (like files or texts), but for passwords, it’s not a major concern for developers. The probability goes way lower for more modern algorithms, so it’s not something developers would consider.

They will generally spend more time on additional security features, like two-factor authentication, new IP address detection, etc. This will enhance the security of their system more than worrying about hash collisions.

In a Nutshell

In short, here are the main takeaways of this article :

  • Two passwords can be different and have the same hash.
  • A collision is the name of this event when using hashing algorithms.
  • The probability of a collision is terribly low for all algorithms.
  • Using a strong hashing algorithm reduce the likelihood of a collision.
  • Collisions are not a major concern for developers when dealing with passwords storage.

Related articles

  • Can 2 Files Have the Same MD5 Hash? (and why)
  • MD5 vs SHA256: Which is Better? (Speed, Safety, …)
  • 3 Reasons why MD5 is not Secure

Whenever you’re ready for more security, here are things you should think about:

- Break free from Gmail:You should be able to choose what happens to your data. With Proton, only you can read your emails.Get private email.

- Protect yourself online:Use a high-speed Swiss VPN that safeguards your privacy. Open-source, no activity logs.Get Proton VPN risk-free.

- Master Linux commands:A sure method to learn (and remember) Linux commands. Useful ones only, one at a time, with clear explanations.Download the e-book.

Can Two Passwords Have The Same Hash? (Why?) – InfosecScout (2024)

FAQs

Can two different passwords have the same hash? ›

There are a few limitations for hash functions, such as hash collisions. It's when two different inputs have the same hash output. However, the probability of a collision in most hashing algorithms is exceedingly low, especially in modern functions, so it shouldn't be a big issue.

Can two things have the same hash? ›

1) If two objects are equal (i.e. the equals() method returns true), they must have the same hashcode. 2) If the hashCode() method is called multiple times on the same object, it must return the same result every time. 3) Two different objects can have the same hash code.

Can two different messages produce the same cryptographic hash justify your answer? ›

TL;DR: It's mathematically certain there are distinct messages with the same hash; yet by design a good hash makes it practically impossible to exhibit any concrete example of such collision. There is one (not 2744) hash codes for each message, because a hash function is a function.

What could be implemented to prevent both password hashes from being the same? ›

By adding randomness to the original plaintext password value before hashing, salting ensures that a different hashed value is generated. Salting is an additional layer of security to prevent, or at least minimize, the possibility of password compromise by the following three primary attack vectors.

Can 2 different inputs have the same hash? ›

Determinism in hash functions ensures that providing the same input twice (i.e. providing the same document) will result in the same hash value; however, providing different inputs (i.e. providing two different documents) will result in two different hash values.

How can two different files have the same hash? ›

A: An SHA-1 hash value is a 40-character string that identifies the contents of a file. If two files have the same contents then it's probable they will have the same SHA-1 hash value. However, please note that it is possible to create two completely different files that have the same SHA-1 hash value.

Is it possible to get the same hash? ›

You asked Can two different files have the same hash? The answer is Yes — it is POSSIBLE. Exactly how possible depends on the hash algorithm you're using. Remember that a hash function is any function that deterministically maps an arbitrary-sized input to a fixed-size output.

Can two strings have the same hash? ›

If two string objects are equal, the GetHashCode method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code.

Can two hash codes be equal? ›

If two objects have the same hashcode then they are NOT necessarily equal. Otherwise you will have discovered the perfect hash function. But the opposite is true: if the objects are equal, then they must have the same hashcode .

Can two messages have the same hash? ›

It is easy to compute the hash value for any given message. It is almost impossible to generate a message from a given hash. It is impossible to modify a message without changing the hash. It is impossible to find two different messages with the same hash.

Can two hash values be alike? ›

In computer science, a hash collision or hash clash is when two distinct pieces of data in a hash table share the same hash value. The hash value in this case is derived from a hash function which takes a data input and returns a fixed length of bits.

Can two keys have same hash value? ›

In a HashMap, when two keys have the same hash code, a collision occurs. When this happens, the keys are stored in the same bucket, which is a linked list of entries.

Does the same password have the same hash? ›

What's worse for the hacker is that every salt is unique, which means that every user who has come up with the same password as me has a different hash. The attacker has to go through this common password + salt = hash process individually for each user in the database.

What technique creates different hashes for the same password? ›

Salting is a concept that typically pertains to password hashing. Essentially, it's a unique value that can be added to the end of the password to create a different hash value.

What can hackers do with password hashes? ›

If hackers have a database of hashed passwords and there are no particular targets, they can attempt to figure out the passwords for anyone in the database. If they succeed, they may be able to access their accounts.

Are password hashes unique? ›

Password hashing is a process in which algorithms turn plaintext passwords into complex strings of numbers and letters, known as ciphertext. If you run a plaintext password (or any word or phrase) through a hashing algorithm, it produces a unique string of characters, sometimes referred to as a hashed value.

Can different data have the same hash? ›

The odds of two random files having the same MD5 hash is 1 in 2^128. Similarly, the odds of a file having the same hash as any particular file is 1 in 2^128. The difficulty of finding two files with the same hash, however, is 1 in ~2^64.

Can two blocks have the same hash? ›

If two blocks with the same hash and the same parent are produced ~simultaneously, one of which is valid, and the other is invalid (but does have valid proof of work), some nodes in the network will see one first, and others will see the other first.

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6617

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.