[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

password validation

Posted on 2005-05-11
12
Medium Priority
?
229 Views
Last Modified: 2010-04-17
what Im trying to do is to verify if the password is higher or equal to 6 and is lower or equal to 12 and that the field passwd1 and passwd2 arte the same, this is what I have what am I doing wrong?

<?PHP
      
      if((($_POST['passwd'] > 6) || ($_POST['passwd'] <12)) && ($_POST['passwd'] != $_POST['passwd2'])){
            echo "Invalid Password";
      }
?>
0
Comment
Question by:jtrudeau
  • 6
  • 5
12 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13980623
> "what Im trying to do is to verify if the password is higher or equal to 6 and is lower or equal to 12 and that the field passwd1 and passwd2 arte the same, this is what I have what am I doing wrong?"

The following seems to meet your spec:

<?PHP
     
     if((($_POST['passwd1'] >= 6) && ($_POST['passwd1'] <= 12)) && ($_POST['passwd1'] != $_POST['passwd2'])){
          echo "Valid Password";
     } else
     {
           echo "Invalid Password";
     }
?>
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13980637
Sorry Jason, that should be:

<?PHP
     
     if((($_POST['passwd1'] >= 6) && ($_POST['passwd1'] <= 12)) && ($_POST['passwd1'] == $_POST['passwd2'])){
          echo "Valid Password";
     } else
     {
           echo "Invalid Password";
     }
?>

0
 

Author Comment

by:jtrudeau
ID: 13980683
k good thanks, except I want to check if its invalid only so what if I will put a ! in the if statement ???
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13980731
To only check if it's invalid, use this:


<?PHP
     
     if( ($_POST['passwd1'] < 6) || ($_POST['passwd1'] > 12) || ($_POST['passwd1'] != $_POST['passwd2']) )
     {
           echo "Invalid Password";
     }
?>

0
 

Author Comment

by:jtrudeau
ID: 13981353
its not working...   it is testing if the number in the passwd is greater or not, its not testing the amount of characters there are in the field :(
0
 

Author Comment

by:jtrudeau
ID: 13981434
password could be numbers or letters
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13981462
Ah, you want to compare the lengths.. It's been a while since I last done some PHP, but this should do it:

<?PHP
     
     if( (count($_POST['passwd1']) < 6) || (count($_POST['passwd1']) > 12) || ($_POST['passwd1'] != $_POST['passwd2']) )
     {
           echo "Invalid Password";
     }
?>


Note the use of the count() function.
0
 

Author Comment

by:jtrudeau
ID: 13981534
count() is to count the number of records
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13981683
how about sizeof() ? ie:

<?PHP
     
     if( (sizeof($_POST['passwd1']) < 6) || (sizeof($_POST['passwd1']) > 12) || ($_POST['passwd1'] != $_POST['passwd2']) )
     {
           echo "Invalid Password";
     }
?>
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13981715
Ah, that's an alias of count(), the strlen() function should do it, give this a go:


<?PHP
     
     if( (strlen($_POST['passwd1']) < 6) || (strlen($_POST['passwd1']) > 12) || ($_POST['passwd1'] != $_POST['passwd2']) )
     {
           echo "Invalid Password";
     }
?>

0
 

Author Comment

by:jtrudeau
ID: 13981764
neither work :(
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 total points
ID: 13981821
What means neither work? I think last proposal works correctly, but you can use die()
Also read carefully your variable names.

<?PHP
     // removing some parenthesis
     if ( strlen($_POST['passwd1']) < 6 || strlen($_POST['passwd1']) > 12 || $_POST['passwd1'] != $_POST['passwd2'] )
     {
           die("Invalid Password");
     }
?>

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question