dongshou2024 2017-05-09 23:39
浏览 41

哈希laravel 4.5用户密码

I try to give users ability to change their password in profile page but when they change the password, password will not be hashed.

This is my update function in 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条回答 默认 最新

  • duanniubeng2265 2017-05-09 23:50
    关注

    I solved the issue with using Trim. here is the code for those who need it:

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

报告相同问题?

悬赏问题

  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程