www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Quick question for simple password verification

  1. #1
    Join Date
    Nov 2009
    Posts
    37

    resolved [RESOLVED] Quick question for simple password verification

    I need some help for the following password validation.
    I have the following very simple HTML.

    Code:
    <head>
    <title>Password</title>
    </head>
    
    <body>
    
    <form action="pass.php" method="post">
    
    
    <label for="password">Password</label>
    <input type="password" name="password" id="password" size="15"><br>
    
    <br>
    
    <input type="submit" name="submit" id="submit" value="Submit Order"/>
    
    </body>
    </html>
    Lets say the correct password is "1234"

    What is the content of the pass.php file?
    If the password is 1234 then the PHP displays "Your password is correct"
    If the password is not 1234 then the PHP displays "Sorry wrong password try again"

    Thanks in advance

  2. #2
    Join Date
    Dec 2009
    Posts
    19
    Well First i am going to clean up your script so all the tags are closed.
    Code:
    </html><head>
    <title>Password</title>
    </head>
    
    <body>
    
    <form action="pass.php" method="post">
    
    
    <label for="password">Password</label>
    <input type="password" name="password" id="password" size="15"><br>
    
    <br>
    
    <input type="submit" name="submit" id="submit" value="Submit Order"/>
    </form>
    </body>
    </html>
    Now for the "pass.php" page, you need to access the POST variable that is sent through the form
    <form action="pass.php" method="post">

    you need to access the variable with the name 'password'
    <input type="password" name="password" id="password" size="15">

    in php you can access the POST variable with the "$_POST['nameHere']" global

    now for the actual page.
    Code:
    <?php
    $enteredPassword = $_POST['password'];
    if($enteredPassword ==  '1234'){
       echo "Correct Password NMIK";
    }else{
       echo "You just failed epically.";
    }
    ?>
    Last edited by Champloo11; 12-18-2009 at 08:38 PM. Reason: spacing fixes and quote fix.

  3. #3
    Join Date
    Dec 2005
    Posts
    2,984
    Soooo close....equality, not assignment:

    PHP Code:
    <?php
    $enteredPassword 
    $_POST['password'];
    if(
    $enteredPassword == '1234'){
       echo 
    "Correct Password NMIK";
    }else{
       echo 
    "You just failed epically.";
    }
    ?>
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  4. #4
    Join Date
    Dec 2009
    Posts
    19
    Quote Originally Posted by aj_nsc View Post
    Soooo close....equality, not assignment:

    PHP Code:
    <?php
    $enteredPassword 
    $_POST['password'];
    if(
    $enteredPassword == '1234'){
       echo 
    "Correct Password NMIK";
    }else{
       echo 
    "You just failed epically.";
    }
    ?>
    Thanks man, i'll fix that. I sometimes make that mistake. but it's because i forget to press the button twice

  5. #5
    Join Date
    Nov 2009
    Posts
    37
    Thank you both guys!

  6. #6
    Join Date
    Dec 2005
    Posts
    2,984
    Quote Originally Posted by Champloo11 View Post
    Thanks man, i'll fix that. I sometimes make that mistake. but it's because i forget to press the button twice
    I've done the same more than once.....more than a few times.....probably on a daily basis actually
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles