Secure Password Class
Posted: Thu Aug 30, 2012 9:17 pm
This function will salt a password and stretch it by 5120 rounds of encryption
<?php function passcrypt($username, $password)
{
$coresalt = "XtyuNfG8AaX7CrerGaAaeEacCmQkRygdFvPu34"; /* or whatever random string you like to form the basis of the salt*/
$usersalt = md5($username); /* hashes the supplied username */
$passlen = 6*strlen($password); /* works out the length of the password and mutiplies it by three */
$num1 = substr($passlen, 0, 1); /* selects the first number of the length */
$num2 = substr($passlen, 1, 2); /* selects the second number of the length */
$num3 = $num1 * $num2; /* Multiplies both numbers */
$truesalt = sha1($num3. $usersalt. $coresalt); /* Conbines all variables and hashes the resulting string */
$endresult = $truesalt. ":". $password; /* Conbines $truesalt and $password */
for ($i=1; $i < 5120; $i++) /* Starts for loop and makes 5120 rounds */
{
$endresult = hash("sha256", $endresult); /* Overwrites the variable */
}
return $endresult; /* Returns the variable */This is a similar, yet modified, version of the function used on my site