[英]How can I update user password in Laravel 5?
我使用Laravel 5.7 。
我正在嘗試更新我的用戶密碼
我運行了這個php artisan tinker
然后
>>> bcrypt(12345);
=> "$2y$10$5woTm5/1w.euUliNCujmMu.oYiC.U8YnRpBHVQN/CxyKXAYB.pGiS"
也試過了
>>> Hash::make('12345');
=> "$2y$10$vjCcADglqpHiLI9tTVlJ2OoaaoQq/qqntRaIaEclTh1exq.vdZcxK"
我將哈希更新復制到我的數據庫中
我嘗試使用12345
登錄。 我無法登錄。
我忘了做什么?
嘗試這個 :
$password = 'something';
$user = User::findOrFail($userId);
$user->fill(['password' => Hash::make($password)])->save();
不要忘記使用 App\\User;
您可以通過多種方式實現這一目標。 我將分享2種方法。
假設您要將密碼更新為12345
如果您有權訪問本地設置
在項目的根目錄中,輸入php artisan tinker
當你在 shell 模式下,輸入bcrypt('12345')
你應該得到哈希密碼。
Psy Shell v0.9.9 (PHP 7.1.4 — cli) by Justin Hileman
>>> bcrypt('12345')
=> "$2y$10$9ruOL7x2T2Utejl96Mp2MOh2xQB/I2R/R0SMp3G55LokeoWGjpuR2"
>>>`
如果您無法訪問本地設置,則可以通過此站點生成哈希
http://www.passwordtool.hu/php5-password-hash-generator
當你有新的散列時,復制它。
嘗試這個:
$user = App\User::where('email', 'user@example.com')->first();
$user->password = Hash::make('password');
$user->save();
這將創建一個哈希密碼並將其保存給用戶,前提是您能夠使用電子郵件地址獲取用戶。
您還可以使用 id 或您擁有的任何其他唯一標識符來更新用戶。 例如,如果你有 id,那么試試這個:
$user = App\User::where('email', 'user@example.com')->first();
$user->password = Hash::make('password');
$user->save();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.