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
https://forums.phpfreaks.com/topic/133891-is-my-salted-hash-ok-to-use/
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.

 

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

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.