Best Practice: Encrypt() vs hash() for password storing? Also, salt storing?
I'm trying to expand my knowledge on security, reading many articles about the different methods to doing so. I've found the easiest two solutions to use, and that is Encrypt() and hash(). Here's how I'm using them -- I'm looking for which would be better security.
For both methods, I am using a salt.
<cfset salt = generateSecretKey('AES')>
<cfset password = FORM.Password>
With encrypt, this is all it takes:
Encrypt(password, salt);
With hash, i'm doing:
hash(password & salt, 'SHA-512', 'UTF-8' );
I can also loop the hash several times to give it more variation:
hashed = hash( password & salt, arguments.algorithm, 'UTF-8' );
for (i = 1; i LTE 1024; i=i+1) {
hashed = hash( hashed & salt, arguments.algorithm, 'UTF-8' );
}
So which method is going to be better protection if someone happened to come upon encrypted password information? Is there a better (free/built-in) method than what I've described?
Also, since both methods will require the original salt used, what's the best procedure for storing the salt? In another database? I've seen some examples store it as a Request variable in application.cfc, but that would allow anyone who has access to the code to see it.
