Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-30-2005, 06:22 AM   PM User | #1
Crazydog
Regular Coder

 
Join Date: May 2005
Posts: 224
Thanks: 1
Thanked 0 Times in 0 Posts
Crazydog is an unknown quantity at this point
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?
Crazydog is offline   Reply With Quote
Old 07-30-2005, 11:14 AM   PM User | #2
mrruben5
Regular Coder

 
Join Date: Nov 2004
Location: The Netherlands
Posts: 551
Thanks: 0
Thanked 0 Times in 0 Posts
mrruben5 is an unknown quantity at this point
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
__________________
CATdude about IE6: "All your box-model are belong to us"

Last edited by mrruben5; 07-30-2005 at 11:17 AM..
mrruben5 is offline   Reply With Quote
Old 07-30-2005, 08:29 PM   PM User | #3
Crazydog
Regular Coder

 
Join Date: May 2005
Posts: 224
Thanks: 1
Thanked 0 Times in 0 Posts
Crazydog is an unknown quantity at this point
giving me an unexpected )

PHP Code:
foreach($cmp_pass as $key => $value) {
    
$cmp_pass[$key]=md5($value)
}  
//this one 
Crazydog is offline   Reply With Quote
Old 07-30-2005, 09:50 PM   PM User | #4
dumpfi
Regular Coder

 
Join Date: Jun 2004
Posts: 565
Thanks: 0
Thanked 18 Times in 18 Posts
dumpfi will become famous soon enough
Add a ;
PHP Code:
    $cmp_pass[$key]=md5($value); // <-- here 
dumpfi
dumpfi is offline   Reply With Quote
Old 07-30-2005, 10:22 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
As well as:
Code:
if (!in_array($_SESSION['pass'], $cmp_pass) {
Need to close 'er up.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:55 AM.


Advertisement
Log in to turn off these ads.