PDA

View Full Version : Salt Generation (Java)


Tyluur
11-29-2013, 01:04 AM
Does anyone know how to generate a salt?

By salt I mean the table value "salt" which is created randomly when a user is made, and is used to verify the credentials when a user is logging in.

Example salt:

;3hTgCLfyOuw|8!A8_Lgjf3|68(IXp

tbworld
11-29-2013, 03:27 AM
This should work:


function createUserSalt()
{
$saltlength = 32;
$salt = '';

for ($i = 0; $i < $saltlength; $i++)
{
$salt .= chr(rand(33, 126));
}
return $salt;
}