2
0
Files
2026-04-28 13:27:52 +02:00

33 lines
794 B
PHP

<?php
/**
* Check password strength (2/2)
* @param string $password password to check
* @return bool - true or false
*/
function checkPasswordStrength(string $password): bool {
$strength = 0;
//check length
$length = strlen($password);
if($length >= 8) $strength++;
//check if caps
if(preg_match('/[A-Z]/', $password)) $strength++;
//check if lower cases
if(preg_match('/[a-z]/', $password)) $strength++;
//check if numbers
if(preg_match('/[0-9]/', $password)) $strength++;
//check if spec. chars
if(preg_match('/[^a-zA-Z0-9]/', $password)) $strength++;
// valid password: #Test12345
return($strength >= 5);
}
function isValidEmail(string $email):bool {
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}