Skip to content

Instantly share code, notes, and snippets.

@lucasgio
Created May 22, 2023 17:32
Show Gist options
  • Save lucasgio/eac45d2845342acdb84b346a9c48b356 to your computer and use it in GitHub Desktop.
Save lucasgio/eac45d2845342acdb84b346a9c48b356 to your computer and use it in GitHub Desktop.
Password Strenght
<?php
declare(strict_types=1);
class PasswordCheckTrait
{
public static function check(string $password)
{
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
$specialChars = preg_match('@[^\w]@', $password);
if (!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) < 8) {
return 'La contraseña debe tener al menos 8 caracteres e incluir como mínimo una letra mayúscula, un número y un carácter especial..';
}
return null;
}
public static function convertHash(string $password)
{
return hash('md5',$password);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment