This commit is contained in:
36
api/app/Rules/SenhaAntiga.php
Normal file
36
api/app/Rules/SenhaAntiga.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user