Как правильно сгенерировать Rasmuslerdorf Hash + BCRYPT + SALT

Twix007

Гуру форума
Регистрация
11 Окт 2009
Сообщения
257
Реакции
57
Здравствуйте, не знаю как составить генерирование пароля Rasmuslerdorf Hash + BCRYPT + SALT и прошу помощи:
Пример генерации:
PHP:
$options = [
    'cost' => 7,
    'salt' => 'BCryptRequires22Chrcts',
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
// $2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq

Вот под такой шаблон подогнать (добавить новый вид шифрования нужно)

PHP:
function xorencode($str, $key)
{
while(strlen($key) < strlen($str))
{
$key .= $key;
}
return $str ^ $key;
}

function strtoint($text)
{
$res = "";
for ($i = 0; $i < strlen($text); $i++) $res .= ord($text{$i}) . "-";
$res = substr($res, 0, -1);
return $res;
}

function generate_salt(){
                $numbers = array("0","1","2","3","4","5","6","7","8","9");
                $lcchars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
                $ucchars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
                $symbols = array('!','@','#','$','%','^','&','*','(',')','-','~','+','=','|','/','{','}',':',';',',','.','?','<','>','[');
                $fake_salt = $numbers[array_rand($numbers)] . $lcchars[array_rand($lcchars)] . $ucchars[array_rand($ucchars)] . $symbols[array_rand($symbols)] . $symbols[array_rand($symbols)];
                $salt = str_shuffle($fake_salt);
                return $salt;
        }
      
function hash_encode64($input, $count)
{
    $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    $output = '';
    $i = 0;
    do
    {
        $value = ord($input[$i++]);
        $output .= $itoa64[$value & 0x3f];
        if ($i < $count)
        {
            $value |= ord($input[$i]) << 8;
        }
        $output .= $itoa64[($value >> 6) & 0x3f];
        if ($i++ >= $count)
        {
            break;
        }
        if ($i < $count)
        {
            $value |= ord($input[$i]) << 16;
        }
        $output .= $itoa64[($value >> 12) & 0x3f];
        if ($i++ >= $count)
        {
            break;
        }
        $output .= $itoa64[($value >> 18) & 0x3f];
    }
    while ($i < $count);
    return $output;
}

function hash_xauth($realPass, $postPass)
{
    $cryptPass = false;
    $saltPos = (strlen($postPass) >= strlen($realPass) ? strlen($realPass) : strlen($postPass));
    $salt = substr($realPass, $saltPos, 12);
    $hash = hash('whirlpool', $salt . $postPass);
    $cryptPass = substr($hash, 0, $saltPos) . $salt . substr($hash, $saltPos);
  
    return $cryptPass;
}

function hash_md5($postPass)
{
    $cryptPass = false;
    $cryptPass = md5($postPass);
  
    return $cryptPass;
}

function hash_dle($postPass)
{
    $cryptPass = false;
    $cryptPass = md5(md5($postPass));
  
    return $cryptPass;
}

function hash_cauth($realPass, $postPass)
{
    $cryptPass = false;
    if (strlen($realPass) < 32)
    {
        $cryptPass = md5($postPass);
        $rp = str_replace('0', '', $realPass);
        $cp = str_replace('0', '', $cryptPass);
        (strcasecmp($rp,$cp) == 0 ? $cryptPass = $realPass : $cryptPass = false);
    }
    else
    {
        $cryptPass = md5($postPass);
    }
  
    return $cryptPass;
}

function hash_authme($realPass, $postPass)
{
    $cryptPass = false;
    $ar = preg_split("/\\$/",$realPass);
    $salt = $ar[2];
    $cryptPass = '$SHA$'.$salt.'$'.hash('sha256',hash('sha256',$postPass).$salt);
  
    return $cryptPass;
}

function hash_joomla($realPass, $postPass)
{
    $cryptPass = false;
    $parts = explode( ':', $realPass);
    $salt = $parts[1];
    $cryptPass = md5($postPass . $salt) . ":" . $salt;
  
    return $cryptPass;
}

function hash_ipb($postPass, $salt)
{
    $cryptPass = false;
    $cryptPass = md5(md5($salt).md5($postPass));
  
    return $cryptPass;
}

function hash_xenforo($postPass, $salt)
{
    $cryptPass = false;
    $cryptPass = hash('sha256', hash('sha256', $postPass) . $salt);
  
    return $cryptPass;
}

function hash_wordpress($realPass, $postPass)
{
    $cryptPass = false;
    $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $count_log2 = strpos($itoa64, $realPass[3]);
    $count = 1 << $count_log2;
    $salt = substr($realPass, 4, 8);
    $input = md5($salt . $postPass, TRUE);
    do
    {
        $input = md5($input . $postPass, TRUE);
    }
    while (--$count);
  
    $output = substr($realPass, 0, 12);
  
    $count = 16;
    $i = 0;
    do
    {
        $value = ord($input[$i++]);
        $cryptPass .= $itoa64[$value & 0x3f];
        if ($i < $count)
        $value |= ord($input[$i]) << 8;
        $cryptPass .= $itoa64[($value >> 6) & 0x3f];
        if ($i++ >= $count)
        break;
        if ($i < $count)
        $value |= ord($input[$i]) << 16;
        $cryptPass .= $itoa64[($value >> 12) & 0x3f];
        if ($i++ >= $count)
        break;
        $cryptPass .= $itoa64[($value >> 18) & 0x3f];
    }
    while ($i < $count);
  
    $cryptPass = $output . $cryptPass;

    return $cryptPass;
}

function hash_vbulletin($postPass, $salt)
{
    $cryptPass = false;
    $cryptPass = md5(md5($postPass) . $salt);

    return $cryptPass;
}

function hash_drupal($realPass, $postPass)
{
    $cryptPass = false;
    $setting = substr($realPass, 0, 12);
    $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $count_log2 = strpos($itoa64, $setting[3]);
    $salt = substr($setting, 4, 8);
    $count = 1 << $count_log2;
    $input = hash('sha512', $salt . $postPass, TRUE);
    do
    {
        $input = hash('sha512', $input . $postPass, TRUE);
    }
    while (--$count);

    $count = strlen($input);
    $i = 0;

    do
    {
        $value = ord($input[$i++]);
        $cryptPass .= $itoa64[$value & 0x3f];
        if ($i < $count)
        $value |= ord($input[$i]) << 8;
        $cryptPass .= $itoa64[($value >> 6) & 0x3f];
        if ($i++ >= $count)
        break;
        if ($i < $count)
        $value |= ord($input[$i]) << 16;
        $cryptPass .= $itoa64[($value >> 12) & 0x3f];
        if ($i++ >= $count)
        break;
        $cryptPass .= $itoa64[($value >> 18) & 0x3f];
    }
    while ($i < $count);
    $cryptPass =  $setting . $cryptPass;
    $cryptPass =  substr($cryptPass, 0, 55);

    return $cryptPass;
}
 
А в чем проблема?

PHP:
/*
	$realPass	- Неизменненный пароль
	$salt		- очевидно salt (длина 22 знака)
*/
function rasmuslerdorf ($realPass, $salt){
	return password_hash($realPass, PASSWORD_BCRYPT, array('cost' => 7, 'salt' => $salt));
}
 
Назад
Сверху