
|
View Full Version : Login Validation
Gamenati 03-06-2003, 08:56 PM hey,
ok heres my stituation:
I have one page displaying two text boxes (password and username) thats ok, but on the next page how would i validate the username and password?
BTW heres what the table looks like:
id | username | password
1 BD16088 <password>
jtrovato 03-06-2003, 09:05 PM You would have to explain yourself better.
What service scripting are you using? are you using an SQL database, flat text file, or a static user name/password?
digitok 03-06-2003, 09:08 PM if you're using mysql, and you already know how to connect to the database, you could use:
$q mysql_query("SELECT * FROM <tablename>");
$d = mysql_fetch_array($q);
if (($username == $d['username']) && ($password == $d['password'])) {
echo("Login Successfull");
}
else {
echo("Username or Password incorrect");
}
S. Jackson 03-06-2003, 09:31 PM I don't code PHP so I'm just wondering about this...
When testing for two conditions against two seperate arrays in a single if(), will it try to find $username in <array> then that part is true, then check if $password is in the next array? If so then you could match up the input username and the input password with person A's username and person B's password.
Just wondering.
digitok 03-06-2003, 09:42 PM uhm.... I can't understand what you're saying?
$username will refer to the variable $username
$var["username"] will refer to the "username" value in an array
Gamenati 03-06-2003, 10:35 PM when i go to http://www.gamenationx.com/MM/login.php and type in [username]revolverryan and [password]rmb1990 it works, but when i put in either
[username]saveon and [password]12345 or
[username]BlackDragon465 and [password]unknow
it doesent work. heres the code for the first page:
<html>
<head>
<base href="http://www.gamenationx.com/">
<title>Members Sign in</title>
</head>
<body>
Staff sign in:<br>
<form method="post" action="/MM/page2.php">
Staff Username <input type="text" size="30" name="loginid"><br>
Password <input type="password" size="30" name="loginpword"><br>
<input type="submit" size="30" value="Submit">
</form>
</body>
</html>
and here is the second page's coding :
<?php
$link_id = mysql_connect ("localhost", "gamenat_admin", "rmb1990") or
die ('Cannot connect to the database.');
mysql_select_db ("gamenat_everything");
$q = mysql_query("SELECT * FROM users");
$d = mysql_fetch_array($q);
if (($loginid == $d['username']) && ($loginpword == $d['password'])) {
echo("Login Successfull");
}
else {
echo("Username or Password incorrect");
}
?>
also here is the table structure :
users
userid | username | password
1 | revolverryan | rmb1990
2 | BlackDragon465 | unknow
3 | saveon | 12345
thanks in advance
digitok 03-06-2003, 10:43 PM ok, the code I gave you will only check it against the first row
in the table. If you wanna check it against every row, use this:
<?
$link_id = mysql_connect("localhost","gamenat_admin","rmb1990")
or die ('Cannot connect to the database.');
mysql_select_db("gamenat_everything");
$q = mysql_query("SELECT * FROM users");
// start loop
while ($d = mysql_fetch_array($q)) {
if (($loginid == $d['username']) && ($loginpword == $ ['password'])) {
echo("Login Successfull");
}
else {
echo("Username or Password incorrect");
}
}
// end loop
?>
I've commented the section where the loop is
(it will loop through all of the rows in the table and check it against each one).
I haven't tested this, but test it and tell me how it goes.
Gamenati 03-06-2003, 10:53 PM i got the error:
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/gamenat/public_html/MM/page2.php on line 9
Gamenati 03-06-2003, 10:57 PM ok, i corrected the error but now it displays results for all three:
Username or Password incorrectLogin SuccessfullUsername or Password incorrect
what do i do now?
digitok 03-06-2003, 11:00 PM <?
$link_id = mysql_connect("localhost","gamenat_admin","rmb1990") or die("Cannot connect to the database.");
mysql_select_db("gamenat_everything");
$q = mysql_query("SELECT * FROM users");
$login = false;
while ($d = mysql_fetch_array($q)) {
if (($loginid == $d["username"]) && ($loginpword == $ ["password"])) {
$login = true;
exit;
}
}
if ($login) {
echo("Login Successfull");
}
else {
echo("Username or Password incorrect");
}
?>
digitok 03-06-2003, 11:07 PM Sorry for editing it about 100 times lol, that should work though
Gamenati 03-06-2003, 11:07 PM now, when it checks the first row it stops
<?
$link_id = mysql_connect("localhost","gamenat_admin","rmb1990") or die("Cannot connect to the database.");
mysql_select_db("gamenat_everything");
$q = mysql_query("SELECT * FROM users");
while ($d = mysql_fetch_array($q)) {
if (($loginid == $d["username"]) && ($loginpword == $d["password"])) {
echo("Login Successfull");
exit;
}
else {
echo("Username or Password incorrect");
exit;
}
}
?>
digitok 03-06-2003, 11:14 PM Check my above post again, like I said I kept editing it :P
Gamenati 03-06-2003, 11:18 PM gives me a blank page
digitok 03-06-2003, 11:22 PM hmm it looks fine to me lol can't see why it wouldn't work...
just for fun, try changing
if ($login) {
to
if ($login == "true") {
it shouldn't make a difference but I really can't see anything wrong
Gamenati 03-06-2003, 11:28 PM well, if the info is wrong it says "username or passowrd incorrect"
but if its right is a blank page
im pretty sure the problem is here somewhere:
if ($login == "true") {
echo("Login Successfull");
}
digitok 03-06-2003, 11:31 PM Weird...
<?
$link_id = mysql_connect("localhost","gamenat_admin","rmb1990") or die("Cannot connect to the database.");
mysql_select_db("gamenat_everything");
$q = mysql_query("SELECT * FROM users");
$success = "no";
while ($d = mysql_fetch_array($q)) {
if (($loginid == $d["username"]) && ($loginpword == $ ["password"])) {
$success = "yes";
exit;
}
}
if ($success == "yes") {
echo("Login Successfull");
}
else {
echo("Username or Password incorrect");
}
?>
try that :/
Gamenati 03-07-2003, 07:16 AM well, for one thing you forgot the 'd'
($loginpword == $d["password"]))
Gamenati 03-07-2003, 07:17 AM still aint working
Gamenati 03-07-2003, 07:34 PM i really need this
Gamenati 03-07-2003, 11:23 PM come on
michaeln 03-08-2003, 12:40 AM <?php
$loginid = $_POST['loginid'];
$loginpword = $_POST['loginpword'];
$link_id = mysql_connect ("localhost", "gamenat_admin", "rmb1990") or die ('Cannot connect to the database.');
mysql_select_db ("gamenat_everything");
$q = mysql_query("SELECT * FROM users WHERE username='$loginid';");
if(!mysql_num_rows($q)) die('Username does not exist');
$d = mysql_fetch_array($q);
if (($loginid == $d['username']) && ($loginpword == $d['password'])) {
echo("Login Successfull");
}
else {
echo("Password incorrect");
}
?>
|