In the Following Program Preg_Match not aacepting - symbol.
<?php
/*
* Complete the 'minimumNumber' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER n
* 2. STRING password
*/
function minimumNumber($n, $password) {
// Return the minimum number of characters to make the password strong
$count = 0;
// Return the minimum number of characters to make the password strong
if (!preg_match( '~[A-Z]~', $password)) {
$count += 1;
}
if (!preg_match( '~[a-z]~', $password)) {
$count += 1;
}
if (!preg_match( '~[0-9]~', $password)) {
$count += 1;
}
if (!preg_match( '~[!@#$%^&*()-+]~', $password)) {
echo 'hit';
$count += 1;
}
if ($n + $count < 6) {
$count += 6 - ($n + $count);
}
return $count;
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$n = intval(trim(fgets(STDIN)));
$password = rtrim(fgets(STDIN), "\r\n");
$answer = minimumNumber($n, $password);
fwrite($fptr, $answer . "\n");
fclose($fptr);
The Program which is checking the Strong Password. The Password should be Minimum 6 chacters and it should contain one number, one small case, one upper case and special character. If anything is missing, have to notify that how many characters needed to make the password strong In that block except those everything is accepting. Am I missing something?
Thanks In Advance