調用方法以前要先去引用:數據庫
use Illuminate\Support\Facades\Hash;
能夠調用 Hash 門面上的 make 方法對存儲密碼進行哈希:
加密
$pwd = Hash::make($request->newPassword); //加密存儲
check 方法容許你驗證給定原生字符串和給定哈希是否相等
spa
if (Hash::check('qwe123456', $pwd)) { // 密碼匹配... }
舉例子:.net
1,Hash::make()存儲數據
2,從數據庫獲取全部數據,而後Hash::check()驗證該數據是否在數據庫中已經存儲
/** * 重置密碼方法 * @param Request $request */ public function set_password(Request $request){ $id = Auth::user()->id; $oldpassword = $request->input('oldpassword'); $newpassword = $request->input('newpassword'); $res = DB::table('admins')->where('id',$id)->select('password')->first(); if(!Hash::check($oldpassword, $res->password)){ echo 2; exit;//原密碼不對 } $update = array( 'password' =>hash::make($newpassword), ); $result = DB::table('admins')->where('id',$id)->update($update); if($result){ echo 1;exit; }else{ echo 3;exit; } }
感謝來源:code
https://blog.csdn.net/wangjinbao5566/article/details/53389422blog