37 lines
771 B
PHP
37 lines
771 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Models\Cadastro\SujeitoAtencao\UsuarioHistoricoSenha;
|
|
use Hash;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class SenhaAntiga implements Rule
|
|
{
|
|
private $id;
|
|
|
|
public function __construct($id)
|
|
{
|
|
$this->id = $id;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
$usuarioHistoricoSenha = UsuarioHistoricoSenha::where('usuario_id', $this->id)
|
|
->orderBy('created_at', 'desc')
|
|
->skip(1)
|
|
->first();
|
|
|
|
if ($usuarioHistoricoSenha && Hash::check($value, $usuarioHistoricoSenha->senha)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'A nova senha não pode ser igual a senha antiga.';
|
|
}
|
|
}
|