7 Replies - 659 Views - Last Post: 11 February 2013 - 10:03 PM Rate Topic: -----

#1 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 30-January 13

Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 08:10 PM

Hi can someone show me how to make the password requirement on this form to be at least 4 characters I just have no idea I have been trying different ways and none work. I have posted my code below if you could just show me the code up dated with the way to handel this that would be great thanks in advance.
<?php
function printForm($strMessage){
echo "<strong>" .$strMessage."</strong>";
echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF']. "\" name=\"form\">\n<br>";
echo "Your Name: <input type=\"text\" Name=\"yname\" value=\"" .trim($_POST['yname'])."\"><br>";
echo "Your Email: <input type=\"text\" Name=\"yemail\" value=\"" .trim($_POST['yemail'])."\"><br>";
echo "Username: <input type=\"text\" Name=\"yusername\" value=\"" .trim($_POST['yusername'])."\"><br>";
echo "Password: <input type=\"password\" Name=\"pword\" value=\"" .trim($_POST['pword'])."\"><br>";
echo "Confirm Password: <input type=\"password\" Name=\"cpword\" value=\"" .trim($_POST['cpword'])."\"><br>";


echo "<input type=\"submit\" value=\"send\" Name=\"submit\"/>\n<br>";
echo "</form>\n";
}
?>
<html>
<head>
<title>Self Submitting Sticky Form</title>
</head>
<body>
    <?php
    if(isset($_POST['submit'])){
        $yourname=trim($_POST['yname']);
        $youremail=trim($_POST['yemail']);
        $yourusername=trim($_POST['yusername']);
		$yourpassword=trim($_POST['pword']);
        $yourcpassword=trim($_POST['cpword']);


       if ($yourname==''){
        $strMessage='Please enter your name.';
        printForm($strMessage);
        }
        elseif ($youremail==''){
		        $strMessage='Please enter your email.';
		        printForm($strMessage);
        }
        elseif ($yourusername==''){
				        $strMessage='Please enter your username.';
				        printForm($strMessage);
        }
        elseif ($yourpassword==''){
				        $strMessage='Please enter your password.';
				        printForm($strMessage);
        }
        elseif ($yourcpassword==''){
				        $strMessage='Please confirm your password.';
				        printForm($strMessage);
        }
        elseif ($yourcpassword != $yourpassword){
				        $strMessage='passwords must match.';
				        printForm($strMessage);
        }



        else{
        $strMessage='Thank you. your information was sent.';
        echo $strMessage;
        }
     }
     else{
     $strMessage='Please enter all fields below:';
     printForm($strMessage);
     }
     ?>
     </body>
     </html>


Is This A Good Question/Topic? 0
  • +

Replies To: Quick question how to make user use at least 4 characters in password

#2 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,865
  • Joined: 30-April 10

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 08:39 PM

http://php.net/manua...tion.strlen.php
Was This Post Helpful? 0
  • +
  • -

#3 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 30-January 13

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 08:45 PM

View Postlaytonsdad, on 11 February 2013 - 10:39 PM, said:


Thanks I kind of understand I think but I am not sure I am assuming this means to do a if statement asking if password is equal to 4 but I am not sure if I understood completely. I tryed this but it is not correct
  elseif ($yourcpassword=='<=3'){
        $strMessage='password must be at least 4 characters.';
        printForm($strMessage);
        }

This post has been edited by ak4744710: 11 February 2013 - 08:49 PM

Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,865
  • Joined: 30-April 10

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 09:01 PM

View Postak4744710, on 11 February 2013 - 08:45 PM, said:

I tryed this but it is not correct
  elseif ($yourcpassword=='<=3'){
        $strMessage='password must be at least 4 characters.';
        printForm($strMessage);
        }


Your right, that is not correct:
elseif ($yourcpassword=='<=3'){

It should be something like:
//find length of string
$passLength = strlen($_POST['pword']);
if(isset($passLength)&& $passLength >= 4){
   //password is filled and larger than or equal to 4 characters
   //do stuff
}else{
   //Error message
}


This post has been edited by Dormilich: 13 February 2013 - 02:01 AM
Reason for edit:: fixing the code

Was This Post Helpful? 0
  • +
  • -

#5 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 30-January 13

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 09:06 PM

Thank you I will try to work with it and see if I can get it now I had found a code similar on the web earlier but I was not able to get it to work but most likely a placement issue or something I appreciate your help
Was This Post Helpful? 0
  • +
  • -

#6 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,865
  • Joined: 30-April 10

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 09:21 PM

Take a look into Pseudocode it will help you layout your code better.
Was This Post Helpful? 0
  • +
  • -

#7 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 30-January 13

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 09:49 PM

I got it it is a little different than what you said but it works thanks your guidance did help
 elseif(strlen($yourpassword) <= 3 ){
        $strMessage='passwords must be at least 4 characters.';
        printForm($strMessage);
        }

Never quite could figure out how to fit it in with a regular if statement with the code I already had I am new to this and I am sure it shows lol.
Was This Post Helpful? 0
  • +
  • -

#8 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,865
  • Joined: 30-April 10

Re: Quick question how to make user use at least 4 characters in password

Posted 11 February 2013 - 10:03 PM

Strlen() gives the actual number of characters are in the string. In your example you are testing for lessthan or equal to three not four.

This post has been edited by Dormilich: 14 February 2013 - 12:17 AM
Reason for edit:: removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1