Jump to content

is my salted hash ok to use?


ibinod

Recommended Posts

after working a while i came out with this function for salting my hashes

please suggest me wt i can do to improve it or is it ok to use for my projects

function saltHash($username, $password)
{
$salt = substr($username,0,4); //all username will be atleast 4 chars so i thought good to take only 4 chars
return hash("sha512",$password.$salt);
}

and while authenticating i m checking like this

function checkHash($hash, $username, $password)
{
$saltWas = substr($username, 0, 4);
if($hash == hash("sha512",$password.$saltWas))
{
	return true;
}
return false;
}

 

btw i am using varchar(150) to store the hashes

Link to comment
Share on other sites

Hi Mchl thanks for the suggestion

btw i don't want to use the full name coz every username may not have same length so i thought to use only 4 chars,

 

btw there is one thing i need your suggestion on, since i will be using their username as dynamic salt so wt if a username is needed to be changed in future, after that how can i verify the salt;

wt do u suggest on this.

 

Link to comment
Share on other sites

Here's my test ;)

 

<?php

echo "Ā<br/>";

echo md5("Ā"). "<br/>";

//Ā is unicode 0xC480

echo chr(0xC4).chr(0x80)."<br/>";

echo md5(chr(0xC4) . chr(0x80)) . "\n";

?>

 

 

results

Ā
99c2cdc511a866f109a87f21f336ed94
Ā
99c2cdc511a866f109a87f21f336ed94 

 

ok... so now I see where &#256; come from in your post

Link to comment
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.