【问题标题】:What Kind of Encryption is used by SentrySentry 使用哪种加密方式
【发布时间】:2014-01-15 06:12:08
【问题描述】:

我正在为我创建的现有 Web 应用程序构建 iOS 应用程序。该网络应用程序使用 laravel 和 sentry 来加密密码。必须能够从 iOS 应用程序创建新用户。 Web 应用程序与之对话的服务器是用 php 编写的,但不使用 laravel 或 sentry。 我需要的唯一哨兵功能是他们用来加密密码的那个。

哨兵使用什么函数来散列密码?我说的是 Cartalyst\Sentry\Hashing\NativeHasher

我需要能够复制这个函数并在一个单独的 php 文件中使用它。

【问题讨论】:

    标签: php encryption laravel laravel-4 cartalyst-sentry


    【解决方案1】:

    我找到了这个链接:https://github.com/cartalyst/sentry/blob/master/src/Cartalyst/Sentry/Hashing/NativeHasher.php

    这段代码可能就是你想要的:

    public function hash($string)
    {
        // Usually caused by an old PHP environment, see
        // https://github.com/cartalyst/sentry/issues/98#issuecomment-12974603
        // and https://github.com/ircmaxell/password_compat/issues/10
        if (!function_exists('password_hash')) {
            throw new \RuntimeException('The function password_hash() does not exist, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
        }
    
        if (($hash = password_hash($string, PASSWORD_DEFAULT)) === false) {
            throw new \RuntimeException('Error generating hash from string, your PHP environment is probably incompatible. Try running [vendor/ircmaxell/password-compat/version-test.php] to check compatibility or use an alternative hashing strategy.');
        }
    
        return $hash;
    }
    

    【讨论】:

    • +1 password_hash() "使用[s] bcrypt 算法(PHP 5.5.0 的默认值)"。
    • 为什么password_hash()每次都返回不同的字符串?
    • @735Tesla:因为它会自动生成盐。
    猜你喜欢
    • 2010-12-06
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2020-07-24
    相关资源
    最近更新 更多