phpvalidationpasswordsuser-datapassword-strength

Validate that a password contains an uppercase letter and either a number or a symbol


I am making a method so your password needs at least one capital and one symbol or number. I was thinking of splitting the string in to loose characters and then use preg_match() to count if it contains one capital and symbol/number.

However I did something like this in action script but can't figure out how this is called in php. I can't find a way to put every character of a word in an array.

AS3 example

for(var i:uint = 0; i < thisWordCode.length -1 ; i++)
{
    thisWordCodeVerdeeld[i] = thisWordCode.charAt(i);
    //trace (thisWordCodeVerdeeld[i]);
}

Solution

  • You can access characters in strings in the same way as you would access an array index, e.g.

    $length = strlen($string);
    $thisWordCodeVerdeeld = array();
    for ($i=0; $i<$length; $i++) {
        $thisWordCodeVerdeeld[$i] = $string[$i];
    }
    

    You could also do:

    $thisWordCodeVerdeeld = str_split($string);
    

    However you might find it is easier to validate the string as a whole string, e.g. using regular expressions.