This commit is contained in:
38
api/app/Rules/SenhaFraca.php
Normal file
38
api/app/Rules/SenhaFraca.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Cadastro\SujeitoAtencao\Usuario;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class SenhaFraca implements Rule
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$usuario = Usuario::findOrFail($this->id);
|
||||
|
||||
$validacoes = ['nome', 'data_nascimento', 'email'];
|
||||
|
||||
foreach ($validacoes as $validacao) {
|
||||
similar_text(strtoupper($value), strtoupper($usuario->cidadao[$validacao]), $porcentagem);
|
||||
|
||||
if ($porcentagem > 25) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'A nova senha é fraca.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user