Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.