Jump to content

password salts


RobertP

Recommended Posts

i just read about password salts, and why they are recommended.

i knew about salts for awhile now, but never knew rainbow tables existed.

so i am updating my encryption for my project i am working on.

 

my current function

protected function encrypt($string){
	return hash('sha1',base64_encode($string));
}

 

my possible updated function (salt length is 8)

protected function encrypt($string){
	return hash('sha1',base64_encode($string.substr(0,(strlen($string)-*-1)));
}

 

Link to comment
https://forums.phpfreaks.com/topic/247544-password-salts/
Share on other sites

Problem 1: the craziness of

substr(0,(strlen($string)-*-1)

 

Problem 2: You can't use part of the password to generate a salt. The salt has to be completely unrelated.

Create a random salt and store it along with the password. Don't forget to use it when verifying passwords.

Link to comment
https://forums.phpfreaks.com/topic/247544-password-salts/#findComment-1271202
Share on other sites

What extra query?  You need to return two things:

 

The hashed password.

The salt.

 

That's as simple as "SELECT password, salt FROM table_name WHERE user_name = $user_supplied_name"  Two columns fetched with one query.

 

Now for what to use for a salt, I've always liked using the timestamp of when a user registers.  It's a unique value for each user and trivial to generate.

Link to comment
https://forums.phpfreaks.com/topic/247544-password-salts/#findComment-1271227
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.