蛋糕PHP如何外部生成其密码

CakePHP how to generate its password external

本文关键字:密码 何外部 PHP 蛋糕      更新时间:2023-09-26

CakePHP 如何生成其外部密码

习惯使用php,我有一个需要与CakePHP集成的应用程序。

基本上,我正在尝试创建一个登录表单,该表单可以使用与CakePHP相同的哈希和加密方法。

我研究了几个文件,如蛋糕PHP的安全组件和AuthComponent,这就是我得出的

$string = "demopassw0rd";
$type = null;
$salt = "mySALT";
$string = $salt . "demo1234";
$stringnew = sha1($string);
echo md5($stringnew);
echo "    SPACES        ";
$stringnew2 = bin2hex(mhash(MHASH_SHA256, $string));
echo md5($stringnew2);

//Below is the real code.
                if ($salt) {
                        if (is_string($salt)) {
                                $string = $salt . $string;
                        } else {
                                $string = $salt . $string;
                        }
                }
                if (empty($type)) {
                        $type = $hashType;
                }
                $type = strtolower($type);
                if ($type == 'sha1' || $type == null) {
                        if (function_exists('sha1')) {
                                $return = sha1($string);
                                return $return;
                        }
                        $type = 'sha256';
                }
                if ($type == 'sha256' && function_exists('mhash')) {
                        return bin2hex(mhash(MHASH_SHA256, $string));
                }

使用上述从蛋糕 php 中提取的方法,我无法检索存储在 mysql 中的相同密码哈希。

我正在尝试创建一个哈希方法,以便我可以创建另一个不是 cakephp 框架的登录表单,并且能够使用与驻留在同一服务器中的 cake php 软件相同的登录表。

 * The level of CakePHP security.
 */
        Configure::write('Security.level', 'medium');
/**
 * A random string used in security hashing methods.
 */
        Configure::write('Security.salt', 'mySALT');
/**
 * A random numeric string (digits only) used to encrypt/decrypt strings.
 */
        Configure::write('Security.cipherSeed', '65986349865349087509054352724');

如何使用上面的配置来制作我自己的哈希方法,该方法可以将我的输入字符串哈希为与我使用 cakephp 存储在 mysql 中的内容相同

我为上述配置解释的蛋糕php哈希方法是

首先

$salt . $string to form a $string value
then sha1($string) and then md5($string)
or bin2hex with the sha264 ($string) and then md5(string)

但是我都尝试过但都未能获得与蛋糕 php 相同的哈希

另一种选择可能是在您的蛋糕应用程序中调用网络服务。 考虑到这一点,您可以从任何语言或应用程序调用它...... 有了这个,你正在使用蛋糕的机制,就像马克说的"使用现有类",但以另一种形式......