1

trying to think of a way to allow me to check an input password against that of the database.

For the database value I am using the Auth feature. So far I have:

$currentPassword = Auth::user()->password;
$passwordInput = Input::get('password-old');

if (isset($passwordPassword) && !Hash::check($passwordInput, $currentPassword))
{
return Redirect::to('/updatepassword')->with('incorrectPassword', '1');
}

I am then checking for the incorrectPassword sent with the redirect. This works, but its ugly. I want to create a custom validation where I can check the field against a given value.

So:

'password' = > 'checkMatch:$checkValue'

Or something?

Any help on this? I have looked at how to implement custom validation rules but cant get it into my head without a working example.

1 Answer 1

2

Validator::extend('checkMatch', function($attribute, $value, $parameters)
{
   if (count($parameters) < 1)
      throw new InvalidArgumentException("Validation rule checkMatch requires at least 1 parameters.");

   return Hash::check($value, $parameters[0]);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, how would this be used? As in 'password' => 'required|checkMatch:?'
Yes, 'password' => 'required|checkMath:yourPasswordHere'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.