note 110514 modified in function.crypt by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Dec 2012 14:24:51 +0000 |
| Subject: | note 110514 modified in function.crypt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192333@lists.php.net to get a copy of this message | ||
Along the lines of the md5crypt, but for blowfish
<?php
function blowfishCrypt($password,$cost)
{
$chars='./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$salt=sprintf('$2a$%02d$',$cost);
for($i=0;$i<22;$i++) $salt.=$chars[rand(0,63)];
return crypt($password,$salt);
}
//Example:
$hash=blowfishCrypt('password',10);
if(crypt('password',$hash)==$hash){ /*ok*/ }
?>
--was--
Along the lines of the md5crypt (5 notes down), but for blowfish
<?php
function blowfishCrypt($password,$cost)
{
$chars='./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$salt=sprintf('$2a$%02d$',$cost);
for($i=0;$i<22;$i++) $salt.=$chars[rand(0,63)];
return crypt($password,$salt);
}
//Example:
$hash=blowfishCrypt('password',10);
if(crypt('password',$hash)==$hash){ /*ok*/ }
?>
http://php.net/manual/en/function.crypt.php