Logo  

CS479/579 - Web Programming II

Displaying ./code/Sessions/password.php

<?php

function gensalt()
{
  $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.";
  $s = "";
  for($i = 0; $i < 15; $i++)
    $s .= $chars[rand(0,63)];

  return $s;
}

$password = "foobar123456";

$salt = '$6$rounds=5000$' . gensalt();

$passwd = crypt($password, $salt);
echo $passwd . "\n";


$pos = strrpos($passwd, "$");
$hsalt = substr($passwd, 0, $pos);

echo $hsalt . "\n";

$input = "foobar123457";
$hash = crypt($input, $hsalt);
echo $hash . "\n";

?>