2
0
Files
ausbildungschule/Zweites Jahr/unterrichts_projekt/portal/functions.php

47 lines
1.0 KiB
PHP

<?php
/**
* Check password strength (1/2)
* @param string $password password to check
* @return bool - true or false
*/
function isStrongPassword(string $password): bool
{
// min. 8 Zeichen, 1 Kleinbuchstabe, 1 Großbuchstabe, 1 Zahl, 1 Sonderzeichen
return (bool) preg_match(
'/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).{8,}$/',
$password
);
}
/**
* 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++;
return($strength >= 5);
}