哈希laravel 4.5用户密码

时间:2017-05-09 23:39:13

标签: php laravel hash

我尝试让用户能够在个人资料页面中更改密码,但是当他们更改密码时,密码将不会被散列。

这是我在usercontroller中的更新功能:

public function update(Request $request, $id)
    {
        $user = User::find($id);
        $this->validate($request, array(
                'name' => 'required|string|max:255',
                'email' => [
                    'required','nullable','string','email','max:255',
                    Rule::unique('users')->ignore($user->id),
                ],
                'gender' => 'required|string',
                'password' => 'nullable|string|min:6|confirmed',
            ));

        $user = User::find($id);

        $user->name = $request->input('name');
        $user->email = $request->input('email');
        $user->gender = $request->input('gender');
        $user->password = $request->input('password');


        $user->save();

        Session::flash('success', 'Your information was successfully updated.');

        return redirect()->route('users.list');
    }

1 个答案:

答案 0 :(得分:0)

我使用Trim解决了这个问题。这是需要它的人的代码:

if (trim(Input::get('password')) != '') {
            $user->password = Hash::make(trim(Input::get('password')));
        }