My solution without functions - only with logic:
<?php
$password = readline();
$valid = true;
//Checking password's length
if (strlen($password) < 6 || strlen($password) > 10) {
echo "Password must be between 6 and 10 characters" . PHP_EOL;
$valid = false;
}
//Checking if the password has only digits and numbers
if (!ctype_alnum($password)) {
echo "Password must consist only of letters and digits" . PHP_EOL;
$valid = false;
}
//Checking if the password has at least 2 numbers
$numberCheck = "";
for ($i = 0; $i < strlen($password); $i++) {
if (ctype_digit($password[$i])) {
$numberCheck .= $password[$i];
}
}
if (strlen($numberCheck) < 2) {
echo "Password must have at least 2 digits" . PHP_EOL;
$valid = false;
}
if ($valid == true) {
echo "Password is valid" . PHP_EOL;
}
I've used: ctype_alnum() and ctype_digit() PHP functions for validation of the password