Web Analytics Made Easy -
StatCounter password script, 2 passwords. - CodingForum

Announcement

Collapse
No announcement yet.

password script, 2 passwords.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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; Jul 30, 2005, 06:17 AM.
    CATdude about IE6: "All your box-model are belong to us"

    Comment


    • #3
      giving me an unexpected )

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

      Comment


      • #4
        Add a ;
        PHP Code:
            $cmp_pass[$key]=md5($value); // <-- here 
        dumpfi
        "Failure is not an option. It comes bundled with the software."
        ....../)/)..(\__/).(\(\................../)_/)......
        .....(-.-).(='.'=).(-.-)................(o.O)...../<)
        ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
        Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

        Comment


        • #5
          As well as:
          Code:
          if (!in_array($_SESSION['pass'], $cmp_pass) {
          Need to close 'er up.
          PHP Code:
          header('HTTP/1.1 420 Enhance Your Calm'); 
          Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

          Comment

          Working...
          X