Laravel 4 - 哈希相同的密码给了不同的价值观 [英] Laravel 4 - Hashing same password gives different values

查看:136
本文介绍了Laravel 4 - 哈希相同的密码给了不同的价值观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用验证::尝试()的方法来验证用户和它不断失败,所以我最终结束了与以下code:

I am trying to authenticate a user using the Auth::attempt() method and it keeps failing, so I eventually ended up with the following code:

$arr = array();
$arr['verified'] = Hash::make('1234') . ' ; ' . Hash::make('1234');
return json_encode($arr);

和这是结果

{"verified":"$2y$10$V4yXBUcxealfLrzOE\/xAD.sJ8qpNhrMA6K6dENBBXYqaVx1zSETgy ; $2y$10$C9xpOWLTUyfy1KL.Y3Tot.KWADmQYFK\/HAf6uZGGXTKcVh52qHS4m"}

正如你所看到的,第一个哈希给出了 $ 2Y $ 10 $ V4yXBUcxealfLrzOE \\ /xAD.sJ8qpNhrMA6K6dENBBXYqaVx1zSETgy 第二散列给 $ 2Y $ 10 $ C9xpOWLTUyfy1KL.Y3Tot.KWADmQYFK \\ / HAf6uZGGXTKcVh52qHS4m

这应该什么都没有做与数据库,即使存放时,我有一个60字符的密码字段。

This should have nothing to do with the database even though when storing, I have a 60 character password field.

任何想法?

推荐答案

这是完全正常的,也是它应该工作的方式。
Laravel使用 Bcrypt 的哈希,并因此产生在哈希处理随机盐。盐将成为这就是为什么你得到两种不同的结果哈希的一部分。

This is perfectly fine and also the way it is supposed to work. Laravel uses Bcrypt for Hashing and is therefore generating a random salt during the hashing process. The salt will be part of the Hash which is why you are getting two different results.

该veryfing算法自动取盐的考虑。这种方法使得使用彩虹表的几乎是不可能的。

The veryfing algorithm is taking the salt into consideration automatically. This method makes the use of rainbow tables nearly impossible.

这是不是一个错误,它没有努力额外的安全性。

It's not a bug, it's extra security with no effort.

鉴于你的例子veryfing对阵双方的哈希将返回true:

Given your example veryfing against both of your hashes will return true:

<?php

$hash1 = Hash::make('1234'); // A hash is generated
$hash2 = Hash::make('1234'); // Another hash is generated that differs from the first one

var_dump(Hash::check('1234', $hash1) && Hash::check('1234', $hash2));

虽然 $ HASH1 $ HASH2 包含不同的哈希值,veryfing对他们给定的基本字符串将计算为真实的。

Although $hash1 and $hash2 contain different hashes, veryfing against them with the given base string will evaluate to true.

生成散列有60​​个字符的长度。所以应该能够保证,在这里散也存储列有60个字符的最小尺寸

这篇关于Laravel 4 - 哈希相同的密码给了不同的价值观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆