更新个人资料密码 laravel 5
update profile password laravel 5
我在 laravel 5.1 工作,我的更新配置文件正在运行,但不会加密,现在无法运行。
当我尝试更新用户 table 时,也会 password_confirmation 字段并导致数据库发生冲突。我不明白。
在表格中说成功但数据库没有更新任何
代码
public function updatePassword() {
$passwordData = Input::except('_token');
$validation = Validator::make($passwordData, User::$passwordData);
if ($validation->passes()) {
array_forget($passwordData,'password_confirmation');
User::where(array(
'password' => Hash::make(Input::get('password'))
));
Session::flash('password', 'Perfil editado com sucesso');
return Redirect::to('backend/perfil/password');
} else {
return Redirect::to('backend/perfil/password')->withInput()->withErrors($validation);
}
}
用户
public static $passwordData = array(
'password' => 'required|confirmed',
'password_confirmation' => 'required'
);
按照这个简单的步骤摆脱任何东西
第 1 步:从表单中获取密码
$PasswordData = Input::all();
第 2 步: 验证您的密码
Validator::extend('pwdvalidation', function($field, $value, $parameters) {
return Hash::check($value, Auth::user()->password);
});
第 3 步: 在您的 User
模型中定义验证规则
public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
'NewPassword' => 'required|confirmed|alphaNum|min:5|max:10',
'NewPassword_confirmation' => 'required',
);
Note :
您可以根据需要定义自己的规则
第 4 步: 如果规则通过,则更新 else 向您的视图抛出错误消息
$validator = Validator::make($PasswordData, User::$rulespwd, $messages);
if ($validator->passes()) {
$user = User::find(Auth::user()->id);
$user->password = Input::get('NewPassword');
$user->save();
return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->with('Messages', 'The Password Information was Updated');
} else {
return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->withErrors($validator);
}
我在 laravel 5.1 工作,我的更新配置文件正在运行,但不会加密,现在无法运行。 当我尝试更新用户 table 时,也会 password_confirmation 字段并导致数据库发生冲突。我不明白。 在表格中说成功但数据库没有更新任何
代码
public function updatePassword() {
$passwordData = Input::except('_token');
$validation = Validator::make($passwordData, User::$passwordData);
if ($validation->passes()) {
array_forget($passwordData,'password_confirmation');
User::where(array(
'password' => Hash::make(Input::get('password'))
));
Session::flash('password', 'Perfil editado com sucesso');
return Redirect::to('backend/perfil/password');
} else {
return Redirect::to('backend/perfil/password')->withInput()->withErrors($validation);
}
}
用户
public static $passwordData = array(
'password' => 'required|confirmed',
'password_confirmation' => 'required'
);
按照这个简单的步骤摆脱任何东西
第 1 步:从表单中获取密码
$PasswordData = Input::all();
第 2 步: 验证您的密码
Validator::extend('pwdvalidation', function($field, $value, $parameters) {
return Hash::check($value, Auth::user()->password);
});
第 3 步: 在您的 User
模型中定义验证规则
public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
'NewPassword' => 'required|confirmed|alphaNum|min:5|max:10',
'NewPassword_confirmation' => 'required',
);
Note :
您可以根据需要定义自己的规则
第 4 步: 如果规则通过,则更新 else 向您的视图抛出错误消息
$validator = Validator::make($PasswordData, User::$rulespwd, $messages);
if ($validator->passes()) {
$user = User::find(Auth::user()->id);
$user->password = Input::get('NewPassword');
$user->save();
return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->with('Messages', 'The Password Information was Updated');
} else {
return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->withErrors($validator);
}