简体   繁体   中英

Rule for Checking Old Password and New Password

I am checking for Old Password and New Password with Confirmation Password.

Here i want to check with whether OldPassword and New Password should not be same.

How can i do this ?

Here is my Rule :

   public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
        'NewPassword' => 'required|confirmed|min:1|max:10',
        'NewPassword_confirmation' => 'required',
        );

Here is my controller code for the validation :

$PasswordData = Input::all();
        Validator::extend('pwdvalidation', function($field, $value, $parameters)
        {
            return Hash::check($value, Auth::user()->password);
        });

        $messages = array('pwdvalidation' => 'The Old Password is Incorrect');

        $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('changepassword')->with('Messages', 'The Password Information was Updated');
        }

Note : I am using model for validation rule.. How can i do this in model ??

Just use the different validation rule - as described in the Laravel docs

public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
    'NewPassword' => 'required|confirmed|min:6|max:50|different:OldPassword',
    'NewPassword_confirmation' => 'required',
    );

Also - why are you limiting a password to 10 chars? That is silly - there is no reason to limit it at all. All your are doing is reducing your application security.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM