Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts

    password script, 2 passwords.

    So I have this script:

    PHP Code:
    <?
    session_start
    ();

    $cmp_pass md5("passtest");


    if(!empty(
    $_POST['pass']))
    {
        
    $_SESSION['pass'] = md5($_POST['pass']);
    }

    if(
    $_SESSION['pass']!=$cmp_pass)
    {
        
    ?>
    How would I make it so there could be two passwords that would work?

  • #2
    Regular Coder
    Join Date
    Nov 2004
    Location
    The Netherlands
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe using array's if you want even more then 2 passwords:

    PHP Code:
    <?php
    session_start
    ();

    $cmp_pass = array();
    $cmp_pass[] = "password1";
    $cmp_pass[] = "password2";
    $cmp_pass[] = "password3";

    //For every password md5 encrypt it.
    foreach($cmp_pass as $key => $value) {
        
    $cmp_pass[$key]=md5($value)
    }

    //remove whitespace and then check for a password
    if(!empty(trim($_POST['pass']))) {
        
    $_SESSION['pass'] = md5($_POST['pass']);
    } else {
        die(
    "No password given!");
    }

    //Is the correct password in the array?
    if (!in_array($_SESSION['pass'], $cmp_pass) {
        die(
    "Wrong password!");
    } else {
        
    //do some stuff you'd like to do here ;)
    }
    ?>
    This also makes it easier if you are storing the passwords in a database
    Last edited by mrruben5; 07-30-2005 at 11:17 AM.
    CATdude about IE6: "All your box-model are belong to us"

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    giving me an unexpected )

    PHP Code:
    foreach($cmp_pass as $key => $value) {
        
    $cmp_pass[$key]=md5($value)
    }  
    //this one 

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Add a ;
    PHP Code:
        $cmp_pass[$key]=md5($value); // <-- here 
    dumpfi

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    As well as:
    Code:
    if (!in_array($_SESSION['pass'], $cmp_pass) {
    Need to close 'er up.


  •  

    Posting Permissions

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