Hash::make与Hash::check
调用方法之前要先去引用:
use Illuminate\Support\Facades\Hash;
可以调用 Hash 门面上的 make 方法对存储密码进行哈希:
$pwd = Hash::make($request->newPassword); //加密存储
check 方法允许你验证给定原生字符串和给定哈希是否相等
if (Hash::check('qwe123456', $pwd)) { // 密码匹配... }
举例子:
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; } }
感谢来源:
https://blog.csdn.net/wangjinbao5566/article/details/53389422