Skip to content

Instantly share code, notes, and snippets.

@rubenestevao
Last active July 30, 2018 19:59
Show Gist options
  • Save rubenestevao/d30febc39c5ccbdc4cae5520c6481102 to your computer and use it in GitHub Desktop.
Save rubenestevao/d30febc39c5ccbdc4cae5520c6481102 to your computer and use it in GitHub Desktop.
Laravel password check rule
<?php
declare(strict_types=1);
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class PasswordCheck implements Rule
{
/**
* @var null|string
*/
protected $guard = null;
/**
* @return void
*/
public function __construct(?string $guard = null)
{
$this->guard = $guard;
}
/**
* @param string $attribute
* @param string $value
* @return bool
*/
public function passes($attribute, $value)
{
return Hash::check($value, Auth::guard($this->guard)->user()->getAuthPassword());
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return trans('validation.password_check');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment