Page 1 of 1

Oddness with Login Script

Posted: Fri Jan 07, 2005 7:58 am
by SilverMist
Hi guys! I'm working on a login script where only me and another administrator can login. (As in it's not a login/register script.) It was all going wonderfully until I went to run it. If you put in the right password, you get to a page that says "Names names names!". If you put in the wrong password, you get something like "Wrong username/password". Or at least your supposed to. As of right now, you get the same page for right or wrong. I got the script when I was browsing through oooold topics, it's off something like page 714. Here's my code:

login.php

Code: Select all

<?php
function index()
{
echo "Login<br>
";
echo "<form action='?mode=login' method='post'>
Username: <input type='text' name='username' size='20'><br>
Password: <input type='password' name='password' size='20'><br>
<input type='submit' value='Log In'>
</form>
";
echo "";
}

$choice=$_GET['mode'];

switch($choice)
{
case "login":

$name = "Kate"; 
$name2 = "Abby"; 

$pass = "misty"; 
$pass2 = "tipsy"; 

if ( ($name != $name2) || ($pass != $pass2) ) { print "Names names names!\n";}

  else { print "Wrong username/password!!\n"; } 
break;


default:
index();
}

?>
Thanks in advance guys!

Posted: Fri Jan 07, 2005 8:42 am
by Chris Corbyn
Slightly confused.

Your code just compare the variables $name and $name2; $pass and $pass2 and that's it.... different outputs but because your if() statement is satisfied based an the values given above your code will always output Names, names, names!....

Is it supposed to check that username and password are correct for the appropriate user?

Re: Oddness with Login Script

Posted: Fri Jan 07, 2005 8:51 am
by Chris Corbyn

Code: Select all

<?php
function index()
{
echo "Login<br>
";
echo "<form action='?mode=login' method='post'>
Username: <input type='text' name='username' size='20'><br>
Password: <input type='password' name='password' size='20'><br>
<input type='submit' value='Log In'>
</form>
";
echo "";
}

$choice=$_GET['mode'];

switch($choice)
{
case "login":

$name = "Kate"; 
$name2 = "Abby"; 

$pass = "misty"; 
$pass2 = "tipsy";

$logins = array();
$logins[$name] = $pass;
$logins[$name2] = $pass2;

if ( isset($logins[$_POST['username']]) && $logins[$_POST['username']] == $_POST['password'] ) { print "Names names names!\n";}

  else { print "Wrong username/password!!\n"; } 
break;


default:
index();
}

?>