Last active
July 30, 2018 19:59
-
-
Save rubenestevao/d30febc39c5ccbdc4cae5520c6481102 to your computer and use it in GitHub Desktop.
Laravel password check rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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