可以使用auth :: attempt()函數獲取使用password_hash()技術存儲在數據庫表中的密碼嗎?如何在laravel5中使用不同加密技術存儲的密碼使用auth :: attempt()
我已存儲使用
password_hash($myPass, PASSWORD_BCRYPT);
我想提前使用
auth()->attempt()
感謝我的密碼。
可以使用auth :: attempt()函數獲取使用password_hash()技術存儲在數據庫表中的密碼嗎?如何在laravel5中使用不同加密技術存儲的密碼使用auth :: attempt()
我已存儲使用
password_hash($myPass, PASSWORD_BCRYPT);
我想提前使用
auth()->attempt()
感謝我的密碼。
我認爲@Spanesh Naik說你可能不需要做任何事情,因爲Laravel使用相同的函數進行自己的哈希。
然而,因爲當你真的想要一個不同的哈希算法更普遍的意義上回答(例如,我有這樣的需要PBKDF2網站),這也很容易更換或用自己的擴展Laravel的散列器。
首先,你需要一個類來實現自定義散列器:在「供應商
class MyHashServiceProvider extends \Illuminate\Hashing\HashServiceProvider
{
public function register()
{
$this->app->singleton('hash', function() {
return new MyHasher;
});
}
}
最後,在你的config/app.php:
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class MyHasher implements HasherContract
{
public function make($value, array $options = array())
{
// make a new hash here
}
public function check($value, $hashedValue, array $options = array())
{
// check an existing hash here
}
public function needsRehash($hashedValue, array $options = array())
{
// return boolean indicating if the hash is using an old algorithm/settings
}
}
然後服務提供商進行註冊'數組,註釋掉該行
Illuminate\Hashing\HashServiceProvider::class
並添加自己的提供者
Some\Namespace\You\Used\MyHashServiceProvider::class;
tnks很多關注@barryp :) :) – Sakil
在內部,Hash :: make()使用bcrypt函數和Blowfish算法進行加密。對於php> 5.5,使用password_hash()和password_verify()函數。所以你可能有運氣。你爲什麼不嘗試實施它 –
Tnks @Spanesh Naik.Can你可以用代碼來解釋一下它嗎?將非常感激。:) :) – Sakil