homepage
Menu
Open menu
  • Training
    Go one level top Back

    Training

    • Courses

      Build cyber prowess with training from renowned experts

    • Hands-On Simulations

      Hands-on learning exercises keep you at the top of your cyber game

    • Certifications

      Demonstrate cybersecurity expertise with GIAC certifications

    • Ways to Train

      Multiple training options to best fit your schedule and preferred learning style

    • Training Events & Summits

      Expert-led training at locations around the world

    • Free Training Events

      Upcoming workshops, webinars and local events

    • Security Awareness

      Harden enterprise security with end-user and role-based training

    Featured

    Get a Free Hour of SANS Training

    Free Course Demos

    Can't find what you are looking for?

    Let us help.
    Contact us
  • Learning Paths
    Go one level top Back

    Learning Paths

    • By Focus Area

      Chart your path to job-specific training courses

    • By NICE Framework

      Navigate cybersecurity training through NICE framework roles

    • DoDD 8140 Work Roles

      US DoD 8140 Directive Frameworks

    • By European Skills Framework

      Align your enterprise cyber skills with ECSF profiles

    • By Skills Roadmap

      Find the right training path based on critical skills

    • New to Cyber

      Give your cybersecurity career the right foundation for success

    • Leadership

      Training designed to help security leaders reduce organizational risk

    • Degree and Certificate Programs

      Gain the skills, certifications, and confidence to launch or advance your cybersecurity career.

    Featured: Solutions for Emerging Risks

    New to Cyber resources

    Start your career
  • Community Resources
    Go one level top Back

    Community Resources

    Watch & Listen

    • Webinars
    • Live Streams
    • Podcasts

    Read

    • Blog
    • Newsletters
    • White Papers
    • Internet Storm Center

    Download

    • Open Source Tools
    • Posters & Cheat Sheets
    • Policy Templates
    • Summit Presentations
    • SANS Community Benefits

      Connect, learn, and share with other cybersecurity professionals

    • CISO Network

      Engage, challenge, and network with fellow CISOs in this exclusive community of security leaders

  • For Organizations
    Go one level top Back

    For Organizations

    Team Development

    • Why Partner with SANS
    • Group Purchasing
    • Skills & Talent Assessments
    • Private & Custom Training

    Leadership Development

    • Leadership Courses & Accreditation
    • Executive Cybersecurity Exercises
    • CISO Network

    Security Awareness

    • End-User Training
    • Phishing Simulation
    • Specialized Role-Based Training
    • Risk Assessments
    • Public Sector Partnerships

      Explore industry-specific programming and customized training solutions

    • Sponsorship Opportunities

      Sponsor a SANS event or research paper

    Interested in developing a training plan to fit your organization’s needs?

    We're here to help.
    Contact us
  • Talk with an expert
  • Log In
  • Join - it's free
  • Account
    • Account Dashboard
    • Log Out
  1. Home >
  2. Blog >
  3. Password Storage Mistakes
SANS_social_88x82.jpg
SANS Institute

Password Storage Mistakes

July 22, 2014

Steve Kosten is an instructor with the SANS Institute for DEV541: Secure Coding in Java/JEE.

Password Storage Mistakes

I was visiting a web site recently that I haven't visited in many, many years. I tried a few old passwords I used to use before I started using a password storage system, but no luck. I was defeated. Barred from entry into this site. But wait, they have a "Forgot Password" link; knowing I will soon have entry into the site, I confidently click on that link (after entering what I believe my username is). Boom, a few seconds later, I have an email from this web site that I will not name. Opening the email, there it was. The password I had created from ages ago. Head-slap.

The head slap wasn't for me forgetting my password; what were the developers of this site doing storing MY PASSWORD in clear text??!! Where anyone with access to the database could readily read my password along w/ thousands of other users. I was incensed. But wait, while we know that storing passwords in clear text in the database is a big mistake, isn't it possible that my password wasn't stored in clear text, but rather the application stores my password in encrypted form and decrypts it prior to sending out the email. Was I being unjustifiably harsh?

Storing my password using reversible encryption means that my password may be decrypted. Someone who has access to the application's system and key, may also readily access my password and the thousands of users at this site. One compromise of the key and ALL passwords are toast.

Hashing

So I don't like clear text storage of passwords, I don't like my passwords being stored in encrypted form, what do I like? Well, I want to see my password hashed as a message digest, with a few extra steps that I will dive into later. But first, let's review what a message digest is.

Hashing, which results in a message digest, is a one-way operation. When a hash is calculated, the input is provided and the result is a fixed length output. The SHA-512 algorithm has a 64 byte output, the SHA-256 algorithm has a fixed 32 byte output, and the bcrypt algorithm has a fixed 60 byte output. For each of these algorithms, there are an infinite number of potential inputs into the algorithm, but a finite number of potential outputs from the algorithm. That is, there will be more than one input that creates the same output. When this happens, this is called a "collision". There has to be collisions because you can't map infinite input space onto finite output space without collisions. Good cryptographic algorithms make it difficult to find collisions, especially meaningful ones. Moving forward, let's assume we're using good cryptographically strong algorithms that make it extremely hard to find collisions.

So by hashing my password, we've solved the password storage problem. When I first setup my password, the application hashes my password and stores the message digest. When I subsequently login, the application again hashes my clear-text password that I entered and compares it to the message digest previously stored. If they match, then the passwords are the same (again, we're using good cryptographically strong algorithm that makes it very hard to find collisions). We know hashing is irreversible, which means that even the people who have access to the database cannot get my password!! Problem solved!

But we're being too quick, the problem isn't yet solved; people crack passwords. Unfortunately, while hashing is irreversible, passwords that have been hashed can still be cracked. A number of password cracking methods can be used, including password dictionaries, rainbow tables, or brute force. A password dictionary is not just my Webster's unabridged dictionary. It is that Webster's unabridged dictionary in every conceivable language on steroids. It has misspellings of words, numbers added throughout the words, capital variations, lower case variations, mixed case variations. It is huge. A rainbow table is a table that contains the pre-computed hash values for all of the passwords in the password dictionary. During a password attack, looking up a hash value in the rainbow table is much faster than hashing and comparing each value in the password dictionary. The details of how rainbow tables work are out of scope for this blog. For now, know that a very good rainbow table can take up a lot of space on disk and can readily crack most passwords people use.

Salting

So is this hashing useless to store passwords? No. You just need a little something special to make it better. And a little salt does just the trick. Well, actually a big complex salt is better. Suppose I have the following as my password "123456". This would be trivially easy to crack, any dictionary attack or rainbow table could be used to find this password. But suppose the developers, before they hash my password, append a large random character string (aka "salt"). So rather than calculating the hash of 123456, or H(123456), they instead store the following large random character string (salt) along with my password, say "4zLrfqPz!AYrkesHvKb6u?T". When I create my password, the application code creates a salt, stores it, and then calculates the hash of my password concatenated with the generated salt, that is H(password + salt) or in my case H(12345644z!LrfqPzAYrkesHvKb6u?T). When the application developers decided to use salts when hashing, they effectively made my trivially simple password much more complex and made it very unlikely that someone could crack the password on a pre-computed dictionary attack or through the use of a pre-computed rainbow table. Rather, with a sufficiently large random salt, an attacker must create a separate dictionary or rainbow table for each user's password they are trying to crack. This is extraordinarily expensive and that is why strong salts effectively break dictionary attacks and rainbow tables.

It does seem odd that salts are not secret and can be stored right along with the message digest. The use of a salt makes a cracker's job much more difficult. Rather than being able to use one dictionary attack or one rainbow table to try to crack every unsalted password stored, they now need to create one rainbow table or dictionary for each and every password/message digest. That is, in a dictionary attack, if they want to crack my "123456" password, they would need to concatenate my salt in order to crack my password. The next user has a different salt, which forces the attacker to recalculate the hash using the new salt. This makes the attacker's job harder, and slows down the password cracking attack.

But if someone really wants to break into my account, and they have my salt, they can create a rainbow table just to crack my password or they could conduct a brute force attack.

In a brute force attack, one determines the password space and then tries every potential password in the password space. If an application only allows users to have a 1 digit password, then the password space is 10. The potential passwords are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. That is, for a one character password with 10 possible characters, there are 101 possible passwords. If I allow 2 digit passwords, there are 102 (100) possible passwords in the potential password space (0, 1, 2, 3, 4, ?. , 97, 98, 99). By introducing complexity in the passwords, say mixed case alphanumeric up to 10 characters long, the number of potential passwords in the password space becomes 6210 (26 lower case + 26 upper case + 10 digits)10 characters or about 8.4 x 1017 or 840,000,000,000,000,000. Brute force attacks with complex passwords can be difficult. With simpler password requirements that limit the password space, brute force attacks can be more readily done, especially by serializing Graphics Processing Units (GPUs) together to perform the heavy computational load quickly. If you cannot enforce very complex passwords, what else can an application developer do to protect against brute force attacks?

The Work Factor

We can slow them down, to a certain extent. Suppose at my fictional website "myApplication.com", I can authenticate a user in 0.5 seconds, end-to-end from an end user perspective. Suppose my users don't notice or complain about slowness unless I don't respond in 2 seconds. Knowing this, I may wish to authenticate all users in less than 1.5 seconds. So I slow my authentication process down. How does this affect a brute force attacker? The trick is in how I slow my authentication process down.

When I calculate the hash in myApplication.com, if I use a hashing algorithm such as bcrypt, then I can affect the work factor needed to compute the message digest. The bcrypt algorithm allows you to specify the work factor you desire until you get the response time you are seeking; in my case, 1.5 seconds end-to-end. Alternatively, if you want to use a hashing algorithm such as SHA-256 which doesn't have a work factor, you can effectively force it by just iterating the hashes prior to storing. That is, rather than just doing one round of the H(salt+password), I iterate over it thousands of times. In the first iteration of the hashing, I calculate H(salt+password) to get the message digest, or MD1. The second iteration, I calculate the hash of the salt + message digest, or H(salt+MD1) to get MD2. I then continue doing this for thousands of iterations until I slow my authentication speed to levels that don't affect the user but that do slow down an attacker. My end users may not notice that I have a higher workload factor on my bcrypt algorithm or that I'm doing 10,000 iterations on my SHA-256 hashing function, but an attacker who is slowed down by a factor of 10,000 definitely does notice this. It makes my password harder to crack.

And that is just what I want! Well, 2-factor authentication, but that's a topic for another day!

If you are interested in topics like this and other aspects of application security, you may wish to consider looking into DEV541 Secure Coding in Java/JEE: Developing Defensible Applications and DEV544 Secure Coding in .NET: Developing Defensible Applications, which cover topics such as the one covered in this blog and many more.

Steve Kosten is the Denver Chapter President of the Open Web Application Security Project (OWASP) that focuses on information security education related to software applications. He is also co-organizer of AppSec USA 2014. He is an application security specialist who reviews software applications for top 100 firms across multiple industries including the financial, defense, identity management and more. He has a Masters degree in Information Security, and is CISSP and CISM certified.

Share:
TwitterLinkedInFacebook
Copy url Url was copied to clipboard
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Tags:
  • Cloud Security

Related Content

Blog
Coolest Careers Poster
Cloud Security
July 14, 2023
SANSがおすすめするサイバーセキュリティの仕事20選: DevSecOps エンジニア
DevSecOps エンジニアの主な業務や、スキルアップのためのSANSのおすすめのコースを紹介します!
SANS_social_88x82.jpg
SANS Institute
read more
Blog
DevSecOops_Thumbnail_FINAL.png
Cloud Security, DevSecOps
February 10, 2023
What is DevSecOps
Part one of a four-part blog series about what’s needed to shake, shimmy, and shift left
Stacey Dunn
Stacy Dunn
read more
Blog
Cloud Security
December 6, 2019
ASP.NET MVC: Using Identity for Authentication and Authorization
Guest Editor: Today's post is from Taras Kholopkin. Taras is a Solutions Architect at SoftServe, Inc. In this post, Taras will take a look at the authentication and authorization security features built into the ASP.NET MVC framework. Implementing authentication and authorization mechanisms into a...
Taras Kholopkin
read more
  • Company
  • Mission
  • Instructors
  • About
  • FAQ
  • Press
  • Contact Us
  • Careers
  • Policies
  • Training Programs
  • Work Study
  • Academies & Scholarships
  • Public Sector Partnerships
  • Law Enforcement
  • SkillsFuture Singapore
  • Degree Programs
  • Get Involved
  • Join the Community
  • Become an Instructor
  • Become a Sponsor
  • Speak at a Summit
  • Join the CISO Network
  • Award Programs
  • Partner Portal
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
  • Privacy Policy
  • Terms and Conditions
  • Do Not Sell/Share My Personal Information
  • Contact
  • Careers
© 2025 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute. Our Terms and Conditions detail our trademark and copyright rights. Any unauthorized use is expressly prohibited.
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn