Hashing explained: Why it’s your best bet to protect stored passwords (2024)

Hashing makes it harder for attackers to decrypt stored passwords, if used correctly.

Hashing explained: Why it’s your best bet to protect stored passwords (1)

Credit: Lukbar / Getty Images

What is hashing?

Hashing is a cryptographic process that can be used to validate the authenticity and integrity of various types of input. It is widely used in authentication systems to avoid storing plaintext passwords in databases, but is also used to validate files, documents and other types of data. Incorrect use of hashing functions can lead to serious data breaches, but not using hashing to secure sensitive data in the first place is even worse.

Hashing versus encryption

Hashing is a one-way cryptographic function while encryption is designed to work both ways. Encryption algorithms take input and a secret key and generate a random looking output called a ciphertext. This operation is reversible. Anyone who knows or obtains the secret key can decrypt the ciphertext and read the original input.

Hashing functions are not reversible. The output of a hashing function is a fixed-length string of characters called a hash value, digest or simply a hash. These are not necessarily intended to be kept secret because they cannot be converted back into their original values. However, one important property of a hashing function is that when hashed, a unique input must always result in the same hash value. If two different inputs can have the same hash value, it is called a collision and, depending how easy it is computationally to find such a collision, the hash function can be considered broken from a security point of view.

Hashing is almost always preferable to encryption when storing passwords inside databases because in the event of a compromise attackers won’t get access to the plaintext passwords and there’s no reason for the website to ever know the user’s plaintext password. If you’ve ever received those notices that “our representatives will never ask for your password” from various companies, that’s part of the reason why they won’t: They have no use for it because they don’t have your password. They have a non-reversible cryptographic representation of your password—its hash value.

That said, companies who suffer security breaches often misuse the term “encryption” in their public disclosures and advise customers that their passwords are secure because they were encrypted. This is probably because the general audience is not very familiar with the meaning of hashing, so their PR departments want to avoid confusion. It makes it hard for outside observers to assess the risks associated with a breach, however, because if the passwords were truly encrypted then the risk is higher than if they were hashed and the next question should be: Was the encryption key also compromised? Cases of encryption being used instead of hashing for passwords do happen.

In 2013, Adobe suffered a security breach that resulted in information from millions of accounts being stolen, including encrypted passwords. Adobe had updated most of its systems to use hashing, but the breached server was a backup one the company planned to de-commission and that stored passwords encrypted with the Triple DES cipher in ECB mode. While the attackers didn’t obtain the decryption key, the use of this cipher in ECB mode is known to leak information, allowing brute-force attacks to recover a significant number of passwords.

“Encryption should only be used in edge cases where it is necessary to be able to obtain the original password,” the Open Web Application Security Project (OWASP) said in its recommendations for password storage. “Some examples of where this might be necessary are: If the application needs to use the password to authenticate against an external legacy system that doesn’t support SSO [or] if it is necessary to retrieve individual characters from the password. The ability to decrypt passwords represents a serious security risk, so it should be fully risk assessed. Where possible, an alternative architecture should be used to avoid the need to store passwords in an encrypted form.”

How hashing is used in authentication

In authentication systems, when users create a new account and input their chosen password, the application code passes that password through a hashing function and stores the result in the database. When the user wants to authenticate later, the process is repeated and the result is compared to the value from the database. If it’s a match, the user provided the right password.

If the user forgets their password, the password recovery process involves validating their identity—usually by proving ownership of the email that was used to create an account by clicking on a unique password reset link sent via email—and then allowing the user to set a new password and therefore a new password hash in the database. If the password recovery process results in their old password being sent to the user via email or being displayed to them in the browser, then the implementation is insecure and best security practices were not followed.

That said, even if hashing is used, developers can make implementation errors, for example by using a hashing function that is known to be insecure and is vulnerable to brute-force cracking attacks. Examples of such hashing schemes that used to be very popular but have been deprecated are MD5 and SHA-1.

Developed in 1991, MD5 was the de facto hashing function for a long time, even after cryptanalysts showed that it is theoretically insecure. Unfortunately, MD5 is still widely used today in old applications or by developers who don’t understand security. The first partial collision attack was theorized in 1996 and a full collision was demonstrated in 2004. Today, MD5 collisions can be found within seconds on a regular home computer and the algorithm is extremely vulnerable to brute-force attacks.

SHA-1 (Secure Hash Algorithm 1) was designed by the NSA in 1995 and was a recommended NIST standard. The function has been known to be insecure against well-funded attackers with access to cloud computing power since 2005. In 2017, security researchers from Centrum Wiskunde and Informatica (CWI) in the Netherlands, Nanyang Technological University (NTU) in Singapore and Inria in France working with Google proved a practical collision against SHA-1 by producing two different PDF files with the same SHA-1 signature. SHA-1 has been deprecated for TLS certificates and other uses, but it’s still widely used in older devices and systems for a variety of purposes, including validating file signatures in code repositories, software updates and more.

For password hashing and storage a recent IETF draft recommends using Argon2 (the winner of the 2015 Password Hashing Competition), Bcrypt, Scrypt or PBKDF2. However, there is more to hashing than just the algorithm used. For example, a minimum password length of eight characters is also important because it makes brute-force attacks that rely on dictionary attacks—lists of common passwords from other data breaches—much harder.

Each hash function can also be implemented so that multiple iterations, or passes, of the hashing algorithm is performed for each password. This is also known as the work factor and its goal is to make the result more computationally intensive to crack using brute force methods. While a higher work factor increases security, it also makes each hashing operation more computationally intensive and longer because the algorithm is executed multiple times.

“There is no golden rule for the ideal work factor—it will depend on the performance of the server and the number of users on the application,” OWASP said in its recommendations. “Determining the optimal work factor will require experimentation on the specific server(s) used by the application. As a general rule, calculating a hash should take less than one second, although on higher traffic sites it should be significantly less than this.”

Salt and pepper

Another best practice for secure password storage is to combine each password with a randomly generated string of characters called a “salt” and then to hash the result. The salt, which should be unique for every user and password, is then stored along with the hash.

Salting passwords makes certain types of attack much harder or impossible to execute. For example, attackers can pre-compute hashes for a very large number of password combinations and then store them in a database known as a rainbow table. Later when they find a leaked password hash they can just perform a lookup in the database to see if it matches any of the pre-computed hashes. Since salting passwords also changes the resulting hash, such attacks are rendered inefficient.

Salting also prevents attackers from discovering duplicate passwords in a database. Even if two or more users chose the same password, the server generated different salts for them and the resulting hashes will be different. The recommendation is for salts to be at least 16 characters long, which significantly increases the complexity and length of the plaintext strings that need to be cracked using computationally intensive brute force methods.

To add another layer of security, in addition to salts, developers can also combine all passwords with a randomly generated string of at least 32 characters called a pepper. Unlike a salt, which is unique for every password, the pepper is the same for all passwords but should not be stored inside the database. The goal of the pepper is to make it hard for attackers to crack hashes even when they obtain the full database of the application, including the salts.

The pepper can be stored in an application configuration file that is protected with appropriate file system permissions or in a more secure location like a hardware security module (HSM).

“An alternative approach is to hash the passwords as usual and then encrypt the hashes with a symmetrical encryption key before storing them in the database, with the key acting as the pepper,” OWASP said. “This avoids some of the issues with the traditional approach to peppering, and it allows for much easier rotation of the pepper if it is believed to be compromised.”

Upgrading hashes

Applications that use an insecure or weak hashing algorithm should be migrated to modern hashing functions. One way to do this could be to use the old hashes as the input for the new hashing algorithm, essentially re-hashing the old hashes. However, while this solves the immediate problem, it makes the resulting hashes more vulnerable to cracking than if they were generated directly from the original user input.

Because of this, it’s recommended that hashes are regenerated with the new modern algorithm the next time users log in and input their passwords. If the user is not active and doesn’t log in for a certain amount of time, their password can be reset and they can be forced to reset the password when they log in the next time.

Finally, the golden rule for all developers when dealing with cryptography: Don’t design your own custom algorithms. Cryptography is very hard and the algorithms that are standardized and widely used are usually the result of academic research efforts that are subject to peer review from other cryptographers and cryptanalysts.

Related content

  • brandpostSponsored by FortinetStrengthening cyber resiliency through collaboration BySuzanne Spaulding, Fortinet Strategic Advisory CouncilApr 03, 20246 minsSecurity
  • newsUS government blames 2023 Exchange breach on ‘preventable’ security failures by Microsoft The US Department of Homeland Security’s Cyber Safety Review Board is calling for industrywide change to help prevent high-impact situations.Bysascha _brodskyApr 03, 20244 minsData BreachGovernmentData and Information Security
  • newsSecurity concerns could be holding back AI projects While considering AI adoption, most organizations are concerned about data privacy, integrity, and security. ByShweta SharmaApr 03, 20244 minsRisk Management
  • featurePCI DSS explained: Requirements, fines, and steps to compliance Anyone who takes credit card payments needs to adhere to PCI DSS—and may face fines if they failByJosh FruhlingerApr 03, 202413 minsRegulationPCISecurity
  • PODCASTS
  • VIDEOS
  • RESOURCES
  • EVENTS

SUBSCRIBE TO OUR NEWSLETTER

From our editors straight to your inbox

Get started by entering your email address below.

Hashing explained: Why it’s your best bet to protect stored passwords (2024)

FAQs

Hashing explained: Why it’s your best bet to protect stored passwords? ›

Instead, we use a process called hashing to obscure the plaintext password in storage, in a way that ensures we can still verify your password when you log in using plaintext. Hashing is a one-way encryption of the password — with one-way simply meaning that once encrypted the data cannot be decrypted.

Why is hashing good for passwords? ›

Password hashing turns your password (or any other piece of data) into a short string of letters and/or numbers using an encryption algorithm. If a website is hacked, password hashing helps prevent cybercriminals from getting access to your passwords.

Why is hashing the recommended technique for storing passwords? ›

Because hashing is a one-way function (i.e., it is impossible to "decrypt" a hash and obtain the original plaintext value), it is the most appropriate approach for password validation. Even if an attacker obtains the hashed password, they cannot use it to log in as the victim.

What is a hash and why is it useful for protecting privacy? ›

Hashing is a one-way mathematical function that turns data into a string of nondescript text that cannot be reversed or decoded. In the context of cybersecurity, hashing is a way to keep sensitive information and data — including passwords, messages, and documents — secure.

What is the primary purpose of storing passwords as hash values or digests? ›

Password hashing is a one-way function. You can't reverse engineer the process and retrieve or trace back to the original password from its hashed form. Hashing is irreversible and ensures that even if someone gains access to the hashed passwords, they won't be able to decipher them back into the original passwords.

Why use hashing instead of encryption? ›

Encryption techniques protect data in motion. Hashing protects data at rest. Combining these strategies could, in theory, put a strong security boundary around critical assets. But both come with risks and benefits you should know about.

Why should we use hashing? ›

Hashing enables efficient data retrieval in hash tables, especially when dealing with large data sets. It uses functions or algorithms to map object data to a representative integer value. A hash can then be used to narrow down searches when locating these items on that object data map.

What is an example of a password hashing? ›

The same input always generates the same hash, but different inputs produce different hashes. For example, the input "password" might produce the hash "5f4dcc3b5aa765d61d8327deb882cf99", while the input "passw0rd" might produce the hash "6c569aabbf7775ef8fc5705a9f1f9b2f".

What is the best method to hash passwords? ›

Choosing a slow algorithm is actually preferred for password hashing. Of the hashing schemes provided, only PBKDF2 and Bcrypt are designed to be slow which makes them the best choice for password hashing, MD5 and SHA-256 were designed to be fast and as such this makes them a less than ideal choice.

What makes hashing a useful security technique? ›

Hashing is a data security technique used to convert data values into alternate, unique identifiers called hashes for quick and secure access. Hashing can be used for data security because the one-way process prevents access to or tampering with the source data.

What is hashing in simple words? ›

Hashing is the practice of transforming a given key or string of characters into another value for the purpose of security. Unlike standard encryption, hashing is always used for one-way encryption, and hashed values are very difficult to decode.

What is a real life example of hashing? ›

There are many practical examples of hash tables used in every-day life. A popular example is in username-password databases. Every time someone signs up on a website using a username and password, that information must be stored somewhere for later retrieval.

Are hashed passwords vulnerable? ›

Many sites still use simple hashing for password storage and their databases are vulnerable to brute-force attacks if stolen. Even salted passwords can be cracked, it's just a matter of time (with password complexity playing a big part).

What is one advantage to storing the password as a hash? ›

Password hashing adds a layer of security. Hashing allows passwords to be stored in a format that can't be reversed at any reasonable amount of time or cost for a hacker. Hashing algorithms turn the plaintext password into an output of characters of a fixed length.

What is the primary reason for using hash algorithms on user passwords? ›

Hashing algorithms are one-way programs, so the text can't be unscrambled and decoded by anyone else. And that's the point. Hashing protects data at rest, so even if someone gains access to your server, the items stored there remain unreadable.

Why is it a much better idea to hash passwords stored in a file than to encrypt the password file? ›

Password hashing is useful on the server side when server operators don't need to know the plaintext, only that the user knows the plaintext. Hashing is a one-way process that converts a password to ciphertext using hash algorithms. A hashed password cannot be decrypted, but a hacker can try to reverse engineer it.

What is the advantage of hashing trick? ›

The hashing trick is commonly used in NLP tasks, such as text classification, document clustering, and information retrieval. It allows for efficient representation of text features by converting them into fixed-size vectors, reducing memory requirements and computational complexity.

Which algorithm is best for storing passwords? ›

To protect passwords, experts suggest using a strong and slow hashing algorithm like Argon2 or Bcrypt, combined with salt (or even better, with salt and pepper).

Top Articles
Financial adviser (level 4) - apprenticeship training course
How to Get a Personal Loan Without a Credit Check
Will Byers X Male Reader
Dragon Age Inquisition War Table Operations and Missions Guide
Ffxiv Palm Chippings
فیلم رهگیر دوبله فارسی بدون سانسور نماشا
Room Background For Zepeto
Kraziithegreat
Plus Portals Stscg
Becky Hudson Free
Edgar And Herschel Trivia Questions
Sitcoms Online Message Board
Https://Gw.mybeacon.its.state.nc.us/App
What Is A Good Estimate For 380 Of 60
Hillside Funeral Home Washington Nc Obituaries
Marion County Wv Tax Maps
Cta Bus Tracker 77
Dulce
Optum Urgent Care - Nutley Photos
Sunset Time November 5 2022
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
kvoa.com | News 4 Tucson
Horn Rank
Effingham Daily News Police Report
Wbap Iheart
Dell 22 FHD-Computermonitor – E2222H | Dell Deutschland
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
24 Hour Drive Thru Car Wash Near Me
2487872771
Rubmaps H
Learn4Good Job Posting
Http://N14.Ultipro.com
Ixlggusd
Microsoftlicentiespecialist.nl - Microcenter - ICT voor het MKB
Where Do They Sell Menudo Near Me
Kvoa Tv Schedule
Samsung 9C8
Polk County Released Inmates
Omnistorm Necro Diablo 4
Elgin Il Building Department
Maxpreps Field Hockey
9781644854013
Banana Republic Rewards Login
Walgreens Agrees to Pay $106.8M to Resolve Allegations It Billed the Government for Prescriptions Never Dispensed
Entry of the Globbots - 20th Century Electro​-​Synthesis, Avant Garde & Experimental Music 02;31,​07 - Volume II, by Various
VPN Free - Betternet Unlimited VPN Proxy - Chrome Web Store
M&T Bank
Killer Intelligence Center Download
Mcoc Black Panther
6463896344
Call2Recycle Sites At The Home Depot
Cheryl Mchenry Retirement
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6585

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.