没有个懂c++跟php的吗?求php—>c++

aladdin_0 2013-06-06 02:23:40
求以下方法的c++版本:
function hash_password($password, $salt = FALSE, $h_byte_size = FALSE)
{
$hash_algos = array(
128 => 'sha512',
64 => 'sha256',
40 => 'sha1',
32 => 'md5'
);
// Even for md5, collisions usually happen above 1024 bits, so
// we artifically limit their password to reasonable size.
if ( ! $password OR strlen($password) > 250)
{
return FALSE;
}

// No hash function specified? Use the best one
// we have access to in this environment.
if ($h_byte_size === FALSE)
{
reset($hash_algos);
$h_byte_size = key($hash_algos);
}
elseif ( ! isset($hash_algos[$h_byte_size]))
{
// What are they feeding us? This can happen if
// they move servers and the new environment is
// less secure. Nothing we can do but fail. Hard.

die('Fatal Error: No matching hash algorithm.');
}

// No salt? (not even blank), we'll regenerate
if ($salt === FALSE)
{
$salt = '';

// The salt should never be displayed, so any
// visible ascii character is fair game.
for ($i = 0; $i< $h_byte_size; $i++)
{
$salt .= chr(mt_rand(33, 126));
}
}
elseif (strlen($salt) !== $h_byte_size)
{
// they passed us a salt that isn't the right length,
// can happen if old code resets a new password
// ignore it
$salt = '';
}

return array(
'salt' => $salt,
'password' => hash($hash_algos[$h_byte_size], $salt.$password)
);

}
...全文
171 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
aladdin_0 2013-06-09
  • 打赏
  • 举报
回复
引用 7 楼 ppsharp 的回复:
我会C++, 也会PHP。 不过你能把分全给我吗?
只要有帮助,给分小case
aladdin_0 2013-06-09
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
不要做A语言代码修改为B语言代码的无用功。 也不要做用A语言代码直接调用B语言代码库这样复杂、这样容易出错的傻事。 只需让A、B语言代码的输入输出重定向到文本文件,或修改A、B语言代码让其通过文本文件输入输出。 即可很方便地让A、B两种语言之间协调工作。
对于我的项目来说,直接翻译是最简便的方法。
赵4老师 2013-06-09
  • 打赏
  • 举报
回复
CryptEncrypt The CryptEncrypt function is used to encrypt data. The algorithm used to encrypt the data is designated by the key held by the CSP module, which is referenced by the hKey parameter. Important changes have been made to the CryptoAPI in order to support S/MIME e-mail interoperability, which affect the handling of enveloped messages. See the Remarks for CryptMsgOpenToEncode for details. Due to French import laws, the Microsoft CSPs do not allow encryption when the Microsoft® Windows NT® operating system is used in France. Therefore, under this condition, this function will fail with the error NTE_PERM. #include <wincrypt.h> BOOL WINAPI CryptEncrypt( HCRYPTKEY hKey, // in HCRYPTHASH hHash, // in BOOL Final, // in DWORD dwFlags, // in BYTE *pbData, // in/out DWORD *pcbData, // in/out DWORD cbBuffer // in ); CryptDecrypt The CryptDecrypt function is used to decrypt data that was previously encrypted by using the CryptEncrypt function. Important changes have been made to the CryptoAPI in order to support S/MIME e-mail interoperability, which affect the handling of enveloped messages. See the Remarks for CryptMsgOpenToEncode for details. Due to French import laws, the Microsoft CSPs do not allow encryption when the Microsoft® Windows NT® operating system is used in France. Therefore, under this condition, this function will fail with the error NTE_PERM. #include <wincrypt.h> BOOL WINAPI CryptDecrypt( HCRYPTKEY hKey, // in HCRYPTHASH hHash, // in BOOL Final, // in DWORD dwFlags, // in BYTE *pbData, // in/out DWORD *pcbData // in/out );
lucky-lucky 2013-06-09
  • 打赏
  • 举报
回复

<?php
function hash_password($password, $salt = FALSE, $h_byte_size = FALSE)
{
    $hash_algos = array(
        128	 => 'sha512',
        64	 => 'sha256',
        40	 => 'sha1',
        32	 => 'md5'
    );
    // Even for md5, collisions usually happen above 1024 bits, so
    // we artifically limit their password to reasonable size.
    if ( ! $password OR strlen($password) > 250)
    {
        return FALSE;
    }

    // No hash function specified? Use the best one
    // we have access to in this environment.
    if ($h_byte_size === FALSE)
    {
        reset($hash_algos);
        $h_byte_size = key($hash_algos);
    }
    elseif ( ! isset($hash_algos[$h_byte_size]))
    {
        // What are they feeding us? This can happen if
        // they move servers and the new environment is
        // less secure. Nothing we can do but fail. Hard.

        die('Fatal Error: No matching hash algorithm.');
    }

    // No salt? (not even blank), we'll regenerate
    if ($salt === FALSE)
    {
        $salt = '';

        // The salt should never be displayed, so any
        // visible ascii character is fair game.
        for ($i = 0; $i< $h_byte_size; $i++)
        {
            $salt .= chr(mt_rand(33, 126));
        }
    }
    elseif (strlen($salt) !== $h_byte_size)
    {
        // they passed us a salt that isn't the right length,
        //  can happen if old code resets a new password
        // ignore it
        $salt = '';
    }

    return array(
        'salt'	 => $salt,
        'password'	=> hash($hash_algos[$h_byte_size], $salt.$password)
    );

}
?>

c++没有提供sha512,sha256,sha1,md5这几个算法直接可用的函数,要转换需要其它库的支持
ppsharp 2013-06-07
  • 打赏
  • 举报
回复
我会C++, 也会PHP。 不过你能把分全给我吗?
startservice 2013-06-06
  • 打赏
  • 举报
回复
不懂PHP。。。。
qq120848369 2013-06-06
  • 打赏
  • 举报
回复
PHP语法和C有什么区别,自己写。
赵4老师 2013-06-06
  • 打赏
  • 举报
回复
不要做A语言代码修改为B语言代码的无用功。 也不要做用A语言代码直接调用B语言代码库这样复杂、这样容易出错的傻事。 只需让A、B语言代码的输入输出重定向到文本文件,或修改A、B语言代码让其通过文本文件输入输出。 即可很方便地让A、B两种语言之间协调工作。
buyong 2013-06-06
  • 打赏
  • 举报
回复
search: C++ md5 hash
hugett 2013-06-06
  • 打赏
  • 举报
回复
不懂PHP的飘过。。
ztenv 版主 2013-06-06
  • 打赏
  • 举报
回复
了解函数功能,C++重写之

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧