核心PHP中的Laravel Hash相当于什么?

6
我已经有一个网络应用程序,我使用以下代码加密了所有密码:

Hash::make($string);

在核心php中,这个代码的等效语句是什么?这样可以帮助我的安卓开发人员与我的应用程序同步。我尝试使用hash和crypt,但不一样。请帮我解决这个问题,让我的开发人员更轻松地编写后端代码。

你看过那段代码了吗?你应该能自己回答这个问题。 - Lorenz Meyer
LorenzMeyer,我是个初学者。 - Tendulraj
2个回答

3
尝试使用

password_hash($string);

您可以使用以下方式进行验证

password_verify($string,$hash);

希望能对您有所帮助!


为什么在使用相同的字符串时,这个哈希函数返回不同的哈希值? - Floris
1
@Floris 它使用bcrypt,每次生成一个新的盐 - 导致相同字符串的不同哈希值。 - Ajay Kumar Ganesh
啊哈,这解释了很多问题。我看到sha1()为相同的字符串创建相同的哈希值。因此,这就是我需要的内容,以便在不同的2个服务器上比较密码。 - Floris

2

我猜这是Illuminate\Hashing\BcryptHasher::make()方法。你可以查看该类的源代码以了解具体情况:

<?php namespace Illuminate\Hashing;

class BcryptHasher implements HasherInterface {

  protected $rounds = 10;

  public function make($value, array $options = array())
  {
    $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;

    $hash = password_hash($value, PASSWORD_BCRYPT, array('cost' => $cost));

    if ($hash === false)
    {
      throw new \RuntimeException("Bcrypt hashing not supported.");
    }

    return $hash;
  }

要在核心PHP中实现这一点,您需要执行以下操作:

$string = "some string that needs to be hashed";
$hash = password_hash($string, PASSWORD_BCRYPT, array('cost' => 10));

之前的回答简短明了。PHP手册讲得很好。还是谢谢你的回答。 - Tendulraj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接