1

Does adding a constant string that is stored in the code to the password before hashing make it harder for an attacker to figure out the original password?

This constant string is in addition to a salt. So, Hash(password + "string in code added to every password" + randomSaltForEachPassword)

Normally, if an attacker gets their hands on the database, they can possibly figure out someone's password by brute force. The database contains the salts corresponding to each password, so they would know what to salt their brute force attempts with. But, with the constant string in code, the attacker would also have to obtain the source code to know what to append to each of their brute force attempts.

I think it would be more secure, but I wanted to get other people's thoughts, and also make sure I'm not inadvertently making it less secure.

Kyle
  • 21,377
  • 37
  • 113
  • 200

2 Answers2

5

Given that you already have a random salt, appending some other string neither adds nor detracts from the security level.

Basically, it's just a waste of time.

update

This was getting a little long to use the comments.

First off, if the attacker has the database and the only thing you've encrypted is the password then games over anyhow. They have the data which is the truly important part.

Second, the salt means that they have to create a larger rainbow table to encompass the larger password length possibilities. The time this takes becomes impractical depending on salt length and the resources available to the cracker. See this question for a bit more info: How to implement password protection for individual files?

update 2 ;)

It is true that users reuse passwords (as some of the latest hacked sites reveal) and it's good that you want to prevent your data loss from impacting them. However, once you finish reading this update you'll see why that's not entirely possible.

The other questions will have to be taken together. The entire purpose of a salt is to ensure that the same two passwords result in a different hash value. Each salt value would require a rainbow table to be created encompassing all of the password hash possibilities.

Therefore not using a salt value means that a single global rainbow table can be referenced. It also means that if you use just one salt value for all passwords on the site, then, again, they can create a single rainbow table and grab all of the passwords at once.

However, when each password has a separate salt value this means they have to create a rainbow table for each salt value. Rainbow tables take time and resources to build. Things that can help limit the time it takes to create a table is knowing the password length restrictions. For example, if your passwords must be between 7 and 9 characters then the hacker only has to compute hash values in that range.

Now the salt value has to be available to the function that is going to hash a password attempt. Generally speaking you could hide this value elsewhere; but quite frankly if they've stolen the database then they'll be able to track it down pretty easily. So, placing the values next to the actual password has zero impact on security.

Adding an extra bit of characters that is common to ALL passwords adds nothing to the mix. Once a hacker cracks the first one it will be obvious that the others have this value and they can code their rainbow table generator accordingly. Meaning that it essentially saves no time. Further, it leads to a false sense of security on your part which can lead to you making bad choices.


Which leads us back to the purpose of salting passwords. The purpose is not to make it impossible, as anyone with time and resources can crack them. The purpose is to make it difficult and time consuming. The time consuming part is to allow you the time to detect the break in, notify everyone you have to, and enforce password changes in your system.

In other words, once the database is lost then all users should be notified so that they can take the appropriate action of changing their passwords on yours and other systems. The salt is just buying you and them time to do this.

The reason I mentioned "impractical" before with regards to cracking them is that the question is really one of the hacker determining the value of the passwords versus the cost in cracking them. Using reasonable salt values you can drive the computational costs up enough that very few hackers would bother. They tend to be low hanging fruit kind of people; unless you have a reason to be a target. At which point you should look into other forms of authentication.

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245
  • Are you sure? The salt is stored in the database, so if the attacker has the database then they know the salt of each password. But with the string in code, wouldn't the attacker also need to obtain the source code (or figure out what the string is some other way)? – Kyle Mar 22 '11 at 15:46
  • 1 - It's also important that the user's password isn't revealed. Users often use the same password across many different websites, and if my website is hacked, I don't want the hacker to be able to obtain the users' passwords. 2 - Can you provide a link or some elaboration on this? The salt is a known value that appears in the password... 3 - Having a salt means rainbow tables aren't useful, which means each user's hashed password must be brute forced separately. This takes way longer, but it is still possible to retrieve passwords this way. – Kyle Mar 22 '11 at 16:52
  • "Second, now that I think about it, having a known value that appears in every password would actually decrease your security." - no it won't. – Nick Johnson Mar 23 '11 at 00:50
2

This only helps if your threat model includes a situation in which your attacker somehow obtains your password database, but cannot read the secret key stored in your code. For most, this isn't a terribly likely scenario, so it's not worth catering for.

Even in that limited case, it doesn't gain you a great deal of additional security, as the attacker can simply take their own password, and iterate over all possible secret key values. Once they find the right one (because it hashes their own password correctly), they can use that to attack all the other passwords in the database as they would normally.

If you're concerned about storing passwords securely, you should use a standard scheme like PBKDF2, which uses key stretching to make brute forcing much less practical.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198