我正在为我创建的现有 Web 应用程序构建 iOS 应用程序。该 Web 应用程序使用 Laravel 和 Sentry 来加密密码。必须能够从 iOS 应用程序创建新用户。 Web 应用程序与之通信的服务器是用 PHP 编写的,但不使用 Laravel 或 Sentry。 我唯一需要的哨兵功能是他们用来加密密码的功能。
哨兵使用什么函数来哈希密码?我说的是Cartalyst\Sentry\Hashing\NativeHasher
我需要能够复制此函数并在单独的 php 文件中使用它。
最佳答案
我找到了这个链接: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;
}
关于php - Sentry 使用什么类型的加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20804298/