Skip to content

Instantly share code, notes, and snippets.

@martinbean
Created July 28, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbean/49ce0931959ab86ae522 to your computer and use it in GitHub Desktop.
Save martinbean/49ce0931959ab86ae522 to your computer and use it in GitHub Desktop.
Check submitted value matches a hash in Laravel.
<?php
// Definition
Validator::extend('hash_matches', function ($attribute, $value, $parameters) {
return Hash::check($value, $parameters[0]);
});
// Usage
'old_password' => 'required|hash_matches:'.$old_password,
@martinbean
Copy link
Author

A Laravel validation rule for matching supplied strings against a hash. Useful for change password forms where you require the user to supply their current password before changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment