laravel修改密碼及與原密碼Hash::check比較
阿新 • • 發佈:2019-01-05
/** * 重置密碼方法 * @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' =>bcrypt($newpassword), ); $result = DB::table('admins')->where('id',$id)->update($update); if($result){ echo 1;exit; }else{ echo 3;exit; } }