tazzy0429 Posted October 5, 2013 Share Posted October 5, 2013 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Password Strength</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php $password = array( "12?b5A", "A234567?", "aBcdefg?", "Mno edf1?", "abcde1?n", "Sasuke!Naruto9", "Anime_Rules!", "Fairy_Tail2", "Natsu_dragoneal1"); foreach ($password as $Passwordchk){ if( strlen($Passwordchk) < 8 ) { $error .= "Password too short! "; } if( !preg_match("#[0-9]+#", $Passwordchk) ) { $error .= "Password must include at least one number! "; } if( !preg_match("#[a-z]+#", $Passwordchk) ) { $error .= "Password must include at least one letter! "; } if( !preg_match("#[A-Z]+#", $Passwordchk) ) { $error .= "Password must include at least one CAPS! "; } if( !preg_match("#\W+#", $Passwordchk) ) { $error .= "Password must include at least one symbol! "; } if($error){ echo "Your password is invalid: $error"; } else { echo "Your password is strong."; } ?> </body> </html> This is am assignment I have to do to validate passwords. I have to have an array that includes at least 10 passwords and six of those must fail. I have to use regular expressions and the passwords must test to be at least 8 characters, include one uppercase, one lower case, one number and one character that is not a letter. It can also not have any spaces. I have to display if each one is strong enough and display the errors. This is what I have so far but it displays nothing. I am not sure what I have done wrong. I also do not have the code to test for spaces included yet...Could someone point me in the right direction with this....thanks Quote Link to comment https://forums.phpfreaks.com/topic/282728-validation-not-returning-anything/ Share on other sites More sharing options...
jcbones Posted October 5, 2013 Share Posted October 5, 2013 You need a closing brace, right before ?>. This will finish out your foreach loop. You should have error_reporting on full, and display_errors on, and you would have seen the error. Quote Link to comment https://forums.phpfreaks.com/topic/282728-validation-not-returning-anything/#findComment-1452661 Share on other sites More sharing options...
tazzy0429 Posted October 5, 2013 Author Share Posted October 5, 2013 I added the <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Password Strength</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php $password = array( "12?b5A", "A234567?", "aBcdefg?", "Mno edf1?", "abcde1?n", "Sasuke!Naruto9", "Anime_Rules!", "Fairy_Tail2", "Natsu_dragoneal1"); foreach ($password as $Passwordchk){ if( strlen($Passwordchk) < 8 ) { $error .= "Password too short! "; } if( !preg_match("#[0-9]+#", $Passwordchk) ) { $error .= "Password must include at least one number! "; } if( !preg_match("#[a-z]+#", $Passwordchk) ) { $error .= "Password must include at least one letter! "; } if( !preg_match("#[A-Z]+#", $Passwordchk) ) { $error .= "Password must include at least one CAPS! "; } if( !preg_match("#\W+#", $Passwordchk) ) { $error .= "Password must include at least one symbol! "; } if($error){ echo "Your password is invalid: $error"; } else { echo "Your password is strong."; } } ?> </body> </html> closing brace but I still get a blank screen when I try to run. I am using notepad++ to create this . Quote Link to comment https://forums.phpfreaks.com/topic/282728-validation-not-returning-anything/#findComment-1452720 Share on other sites More sharing options...
jcbones Posted October 5, 2013 Share Posted October 5, 2013 I copy/paste'd your code, and ran it. This is what I got: Notice: Undefined variable: error in /var/www/test.php on line 24 Your password is invalid: Password too short! Your password is invalid: Password too short! Password must include at least one letter! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Password must include at least one CAPS! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Password must include at least one CAPS! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Password must include at least one CAPS! Password must include at least one number! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Password must include at least one CAPS! Password must include at least one number! Password must include at least one symbol! Your password is invalid: Password too short! Password must include at least one letter! Password must include at least one number! Password must include at least one CAPS! Password must include at least one number! Password must include at least one symbol! Password must include at least one symbol! Quote Link to comment https://forums.phpfreaks.com/topic/282728-validation-not-returning-anything/#findComment-1452739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.