Jump to content

validation not returning anything


tazzy0429

Recommended Posts

<!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

 

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.