hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Login Validation
Reply

Forum Jump

Login Validation

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 03-06-2003, 08:56 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160

Login Validation


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>



Sponsored Links
  #2  
Old 03-06-2003, 09:05 PM
jtrovato jtrovato is offline
Aspiring Evangelist
 
Join Date: Aug 2002
Location: Long Island
Posts: 427
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?

__________________
John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  #3  
Old 03-06-2003, 09:08 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
if you're using mysql, and you already know how to connect to the database, you could use:

PHP Code:
$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");


__________________
nu-metal.org :: coming soon

Sponsored Links
  #4  
Old 03-06-2003, 09:31 PM
S. Jackson S. Jackson is offline
Newbie
 
Join Date: Mar 2003
Location: Manchester, England
Posts: 8
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.

  #5  
Old 03-06-2003, 09:42 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
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

__________________
nu-metal.org :: coming soon

  #6  
Old 03-06-2003, 10:35 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
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

  #7  
Old 03-06-2003, 10:43 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
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:
PHP Code:
<?
$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.

__________________
nu-metal.org :: coming soon

  #8  
Old 03-06-2003, 10:53 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
i got the error:
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/gamenat/public_html/MM/page2.php on line 9

  #9  
Old 03-06-2003, 10:57 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
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?

  #10  
Old 03-06-2003, 11:00 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
PHP Code:
<?
$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");
}
?>

__________________
nu-metal.org :: coming soon


Last edited by digitok; 03-06-2003 at 11:06 PM.
  #11  
Old 03-06-2003, 11:07 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
Sorry for editing it about 100 times lol, that should work though

__________________
nu-metal.org :: coming soon

  #12  
Old 03-06-2003, 11:07 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
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;

}
}
?>

  #13  
Old 03-06-2003, 11:14 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
Check my above post again, like I said I kept editing it

__________________
nu-metal.org :: coming soon

  #14  
Old 03-06-2003, 11:18 PM
Gamenati Gamenati is offline
Temporarily Suspended
 
Join Date: Jan 2003
Posts: 160
gives me a blank page

  #15  
Old 03-06-2003, 11:22 PM
digitok digitok is offline
Web Hosting Master
 
Join Date: Jan 2003
Location: Perth, WA, Australia
Posts: 1,276
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

__________________
nu-metal.org :: coming soon

Reply

Related posts from TheWhir.com
Title Type Date Posted
MongoHQ Launches New Security Features, Open Sources Startup Security Handbook Web Hosting News 2014-01-30 12:22:00
Microsoft Validates Parallels Hypervisor Under its Server Virtualization Validation Program Web Hosting News 2013-12-20 11:44:13
The Host Group Launches Updated Line of SSL Certificate Options Web Hosting News 2013-06-24 10:14:16
cPanel Conference 2012: What's New with cPanel and WHM with Ken Power Web Hosting News 2012-11-12 13:54:56
DigiCert Launches Extended Validation Code Signing Certificates Web Hosting News 2012-08-15 15:30:28


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?