Laravel 密码确认不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38954531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:18:50  来源:igfitidea点击:

laravel password confirm doesn't work

validationlaravellaravel-5

提问by devnull Ψ

I made sign up form, but there some are problems with passwords. i enter exactly the same passwords in password field and confirm password field but it fails

我制作了注册表单,但密码有问题。我在密码字段中输入完全相同的密码并确认密码字段但它失败了

The password confirmation confirmation does not match.

my sign up form

我的注册表单

<div class="form-group">
   {!! Form::password('password', ['class' => 'form-control','placeholder' => '*Password']) !!}
</div>
<div class="form-group">
   {!! Form::password('password_confirmation', ['class' => 'form-control', 'placeholder' => '*Password Confirm']) !!}
</div>

my validations

我的验证

'password' => 'required|between:8,255',
'password_confirmation' => 'confirmed',

i also try this

我也试试这个

'password' => 'required|between:8,255',
'password_confirmation' => 'required|between:8,255|confirmed',

and this

和这个

'password' => 'required|between:8,255|confirmed',
 'password_confirmation' => 'required|between:8,255|confirmed',

but still doesn't work

但仍然不起作用

回答by Kabir Hossain

This is best approach for password confirmation:

这是密码确认的最佳方法:

  'password' => 'required|between:8,255|confirmed'

Explain:

解释:

confirmed: The field under validation must have a matching field of foo_confirmation.

确认:被验证的字段必须有一个匹配的字段foo_confirmation。

For example, password field named: password

例如,密码字段名为:password

password confirmation field would be: password_confirmation

密码确认字段将是:password_confirmation

Then the confirmed property will add default check for password confirmation.

然后confirmed 属性将添加默认检查密码确认。

回答by Sven van den Boogaart

Try

尝试

 'password' => 'required|between:8,255|confirmed'

Note the confirmed is added to password validation, you dont have to add the rules twice because a confirm field needs to have the same fields.

请注意,确认已添加到密码验证中,您不必两次添加规则,因为确认字段需要具有相同的字段。

回答by Kiran Subedi

Your validation should be like :

你的验证应该是这样的:

'password'              => 'required | confirmed ',
'password_confirmation' => 'required ',

For more details See Here

有关更多详细信息,请参阅此处

回答by Pyton

confirmedmust be passed into passwordvalidation rule:

confirmed必须传入password验证规则:

'password' => 'required|between:8,255|confirmed', 'password_confirmation' => 'required',

'password' => 'required|between:8,255|confirmed', 'password_confirmation' => 'required',

回答by Nirav Bhoi

I am using Laravel 5.2 and I am able to work this out using

我正在使用 Laravel 5.2,我可以使用

'password' => 'required|min:8|same:confirm_password'

回答by Arshid KV

 Validator::extend('old_password', function ($attribute, $value, $parameters, $validator) {
                return Hash::check($value, current($parameters));
            },
                'Current password is wrong!'

            );
            $request->validate([
                'old_password'          => 'required|old_password:' . $user->password,
                'password'              => 'required|confirmed|min:6',
                'password_confirmation' => 'required|same:password'
            ]);

回答by abolfazl_rastegar

$validator_password = validator::make($request->all(), [ 'old_password' => ['required', 'string', 'min:8', 'old_password:' . $user->password], 'new_password' => 'required|confirmed|min:6', 'password_confirmation' => 'required|same:new_password' ]);

$validator_password = validator::make($request->all(), [ 'old_password' => ['required', 'string', 'min:8', 'old_password:' . $user->password], ' new_password' => 'required|confirmed|min:6', 'password_confirmation' => 'required|same:new_password']);