Encrypting Passwords
It is quite obvious that the passwords need to be stored in a encrypted format. One of the following methods could be used to encrypt the passwords
- Password based encryption or two-way technique
- Digests or one-way technique
In the second approach, we can "hash" the password and create a message digest and store the digest. It is impossible to derive the input password from the digest i.e. one way conversion only. When the user enters the password, we can apply the same hashing algorithm to obtain the message digest and then compare the digests to verify the password. There are many hashing algorithms, and they are designed to generate different digests for different input strings i.e. for 2 different input strings/passwords it will not generate same message digest. And also same digest for a single input when hashing is applied. This will make the life of the attacker bit difficult to crack the password once after they have gained access to the password database. But it is still not impossible. Attackers can use brute force or if they already have the digest for dictionary for various hashing algorithms they might be able to crack the simple passwords first which will reveal the algorithm. Later it is a matter of time before they can crack the rest of the passwords.
The concepts "salt" and "iteration" comes into picture here. These techniques make it even more difficult, if not impossible, for an attacker to crack the passwords.
The salt
Salt is nothing but sequence of bytes (typically 6 to 16 bytes) of random data. This data is added to the passwords and hashed together to be converted into a digest. There are 2 types of salts
- Fixed salt --> Same sequence of bytes will be used for encrypting all passwords
- Variable salt --> Random sequence of bytes will be generated for each password. In this case the salt will usually be stored along with the digest in plain format (i.e un-encrypted). The attacker can easily find the salt. But he will have to attack each password separately. We are making his life more more difficult and the next technique will deliver the ultimate punch.
Iteration
Iteration applies to the number of times the hashing is applied on passwords. The input password is hashed and the resultant digest is hashes again, resultant digest is hashes again, and this cycle continues. An iteration count of 1000 is a good level. When verifying the user password 1000 iterators might take few milliseconds. But imagine the case of an attacker who has managed to access the password database. Even if he manages to know the algorithm and found out the salt, for each guess it will take few milliseconds and for an eternity to crack few passwords.