Jump to content

[SOLVED] Multiple Login Names and Passwords...


bizerk

Recommended Posts

I have a script where if the user supplies the correct LOGIN NAME AND PASSWORD, that the user can upload images correctly, and if not it echos "Wrong credentials". I want to make it so there can be more than one username you can use, and more than one password. How can I make it so each user name has it's own password and there is more than one... I tried to do this:

 

if($_POST['Submit']) {
if($name =="example" or "example2"and $password =="pass123" or "pass456")
{
foreach ($_FILES as $key=>$file)
		{
		if (!empty($file['name']))
			{
			uploadFiles($key);
			}
}
		}else{
		echo "Wrong Credentials, Please try to Login Again";
		}
		}

 

That usually works with my other script, but for this one it does not work... :/.

 

Any tips? And how would I make it so that EXAMPLE username ONLY WORKS WITH pass123. I know I could just use mysql, but am lazy. :]

well..

 

if($name =="example" or "example2"and $password =="pass123" or "pass456")

 

could be

 

if($name =="example" && $password =="pass123" || $name =="example2" && $password =="pass123")

 

dunno??

 

but you could make it far more advanced with a function that returns True of match found or False if not and much eaiser to edit than if you put all names and passwords in a huge array

 

If(functioncall($name,$pass)){

Goodpage

}else{

badpage

}

 

functioncall($name,$pass){
$dfdsfds = array("example","password","example2","password2");
check array of names with password mix
for($i=0; $i < count($dfdsfds); $i++
if($dfdsfds[i] == $name && $$dfdsfds[i+1] == $pass)
return True;
}
return False; 
}

 

ya.. something like that

}

<?php
$name  = ...
if($_POST['Submit']) 
{
switch ($name) 
        {
case "username1":
   		if($pass1 != "pass1")
	{
		//kill program - Not the correct password
	}
   		break;
case "username2":
  		if($pass2 != "pass2")
	{
		//kill program - Not the correct password
	}
   		break;
default:
   		echo "No user found";
	//Kill program
        }
//Finish the rest of the coding here
}
?>

 

I think this will work.

 

I am unsure as to the efficiency and safety. Thats a question for someone more experienced. You could just use two different if statements, or combine them into one if() statement. Research your options in the manual. If it grows beyond two users, I would suggest using something like the switch.

Yeah sspoke, that worked perfectly. This got me wondering though. Is there anyway that I can clear a page using php? or Would I have to make it go to another page... I was wondering now that I can make an admin account, that like I could make it so if a user logged in as ADMIN, they could delete all files or something which i have already made the unlink script for. Anyway thats possible?

I dont think you can clear a page but you can make your full admin page from 1 page no need to redirect to more pages just filter out the $_POST data..

 

like if you want to add a file

 

if($_POST['Add']){
echo "the page for adding files";
} elseif($_POST['deletefiles']){
echo "the page for deleting files";
} else {
echo "unknown page some error maybe";
}

 

Ya its like this in the packets..

thatonepage.php?Add

thatonepage.php?deletefiles

 

but thats a GET method  $_GET[]

 

POST is invisble to browsers

 

you can always use a include  header and footer   for the page of the page you want to always to show for design or links w/e

 

 

I could make it so if a user logged in as ADMIN, they could delete all files or something which i have already made the unlink script

 

just  brach your logged in if statement..

 

like

 

<?php 
$name = $_POST['usernamedata'];
$pass = $_POST['passworddata'];

If(functioncall($name,$pass)){


if($_POST['Add']){
echo "the page for adding files";

//ADD here Your Adding files full script

} elseif($_POST['deletefiles']){
echo "the page for deleting files";

// ADD here your unlink script
} else {
echo "unknown page some error maybe";
}

}
?>

 

but that would require the user to put in username/password every time he refreshes page you have to use sessions and cookies its really hard to explain well not hard but its long just download some working login/ cms script and modd it how you like it thats what I always do.

If you're going to do a function w/ both a username and password you want to do something like:

 

login($username,$password){
$una = array('example','example2');
$pwa = array('password','password2');

  if(in_array($username,$una) && in_array($password,$pwa)){
  //good page here
  }else {
  //bad page here
  }
}

//then call the function
$un = $_POST['username'];
$pw = $_POST['password'];
login($un,$pw);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.