Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 01-15-2003, 06:43 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
login script

does anyone have a login script that I can take a look at? mine isn't working quite right, i just want to make sure that I am doing it right.

thanks,

Trevor
__________________
trevor is offline   Reply With Quote
Old 01-15-2003, 07:03 PM   #2 (permalink)
anon
 
Posts: n/a
Well just something like:

Code:
$name=$_GET['name']; $pass=$_GET['pass']; if ($name=="trevor" && $pass=="f00") { print "Security confirmed"; } else { print "evil cracker! NEVER! HAHAHAHA"; }
Or are you working with MySQL/other DB?
__________________
  Reply With Quote
Old 01-15-2003, 07:14 PM   #3 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
I am using MySQL

thanks
__________________
trevor is offline   Reply With Quote
Old 01-15-2003, 07:25 PM   #4 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
does anyone see anything wrong with this code:

<?php

$Array["username"] = trim($Array["username"]);
$Array["password"] = trim($Array["password"]);

// Database
$host = "darkstar";
$user = "root";
$dpassword = "123";
$dbname = "ao_db2003";
$link = mysql_connect($host, $user, $dpassword)
or die("Could not connect");
mysql_select_db("ao_db2003")
or exit("Could not select database");

$query = "Select password from users where(username = '$Array[username]')";
$result = mysql_query ($query, $link)
or die("error2");

while ($row = mysql_fetch_array ($result)) {

if ($row["password"] == $Array["password"]) {

$cpass = $Array["password"];

$cuser = $Array["username"];

setcookie("cuser", $cuser);
setcookie("cpass", $cpass);
$logtime = time();
$logtime2 = $logtime - 600;
$request = mysql_query ("DELETE FROM online WHERE (logtime < $logtime2)")
or die("error1");
$request = mysql_query ("DELETE FROM online WHERE (cuser='$cuser')")
or die("error");

$sql = "INSERT INTO online VALUES ('$cuser','$logtime')";
if (!$result = mysql_query($sql)){echo mysql_error();}

mysql_close($link);
header("location: main.php");

exit;

} else {

mysql_close($link);
header("location: failed.php");
exit;
};

};

mysql_close($link);

?>
__________________
trevor is offline   Reply With Quote
Old 01-15-2003, 08:12 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
de ja vu? =)

i won't go over how to connect to your database again, but lets assume you have your connection script in a php file named connect.php

here's how i would do it.
PHP Code:
<?
include("connect.php");

// query db for a row that matches the user/pass entered
$result=mysql_query("select * from users where user='$user' and pass='$pass'");

// find the number of results found with that query
$num=mysql_numrows($result);

// send to failed.php if 0 results have been found
if($num 1){
  
header("location: failed.php");
} else {
  
header("location: main.php");
}
?>
now this is where sessions would come in handy. what would prevent someone from going directly to main.php ?

so what you can do is just start a session so the user and pass are remembered.

then at the top of each page.. just use code similar to above.

PHP Code:
<?

session_start
();
session_register(user,pass);

include(
"connect.php");

// query db for a row that matches the user/pass entered
$result=mysql_query("select * from users where user='$user' and pass='$pass'");

// find the number of results found with that query
$num=mysql_numrows($result);

// send to failed.php if 0 results have been found
if($num 1){
  
header("location: failed.php");
}

// the difference is that there is no else statement .. you can safeily put the authorized only content below here because if the authentication fails, the user will be sent to failed.php
?>
__________________
sde is online now   Reply With Quote
Old 01-15-2003, 08:26 PM   #6 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
thanks again SDE

I'm gunna send you a fruit basket or something sometime

-Trevor
__________________
trevor is offline   Reply With Quote
Old 01-15-2003, 09:42 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
mm .. ilike apples.
__________________
sde is online now   Reply With Quote
Old 01-16-2003, 06:29 PM   #8 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
ok its not quit working. It takes me to failed.php EVERYTIME. I thought it was working fine last night because I had no users in the database, so it was suppost to take me to FAILED.PHP

in my index page i have the username and password going to Array[username] and Array[password]

PHP Code:
<?
include("connect.php");

$password=$Array[password];
$username=$Array[username];

// query db for a row that matches the user/pass entered
$result=mysql_query("select * from users where username='$username' and password='$password'");

// find the number of results found with that query
$num=mysql_numrows($result);

// send to failed.php if 0 results have been found
if($num 1){
  
header("location: failed.php");
} else {
  
header("location: main.php");
}
?>
thanks,

Trevor
__________________
trevor is offline   Reply With Quote
Old 01-16-2003, 06:37 PM   #9 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
my gosh...You must have the mummy's curse. :p


sorry, cant help...I am learning PHP


BTW. Do you know if Sams PHP is a good PHP book? Its the e-book I have.

Thanks

Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-16-2003, 06:46 PM   #10 (permalink)
anon
 
Posts: n/a
Are you sure the contents of the MySQL are correct (ie you enterted in the correct stuff?)? Have you tried multiple times?
__________________
  Reply With Quote
Old 01-16-2003, 06:54 PM   #11 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
"Sams teach yourself PHP4 in 24 hours" is a great book,, i bought it at zellers for $19cdn from one of those big bins

...I should probably read it If you already have it installed you can save 4 hours

=--------------------------------------------=

Anyways.....

yes i do seem to be cursed. none of this stuff is working. I have tried everything I can think of before posting here. I am absolutly sure that the username and password I am entering is corect.
__________________
trevor is offline   Reply With Quote
Old 01-16-2003, 06:57 PM   #12 (permalink)
anon
 
Posts: n/a
Trying putting in like 2 or 3 just to make sure . Also try using phpMyAdmin (I believe it does this stuff, entering crap into MySQL, check it out at sourceforge)
__________________
  Reply With Quote
Old 01-16-2003, 06:59 PM   #13 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
here is my code for the login page:

PHP Code:
<?
include("connect.php");
?> 

<html>
<head>
<title>login page</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#686464">
<center>
<br>
<br>
<br><br><br>
 
<img src="assets/ao.jpg">
</center>
<STYLE type=text/css>
a:link { color:#0a527f; text-decoration:none;}
a:visited { color:#0a527f; text-decorations:none;}
a:hover { text-decoration:none; color:#000000;}
</STYLE>

<form name="login" method="post" action="login.php">
<center>
<table width="18%" border="0">
<tr>
<td>
Login:
</td>
<td>
<input type="text" name="Array[username]">
</td></tr>
<td>
Password:
</td>
<td>
<input type="password" name="Array[password]">
</td></td></table><br><br>
<input type="submit" name="Submit" value="Login">

<br><br><br>
- [ <a href="register.php">r e g i s t e r</a> | <a href="lostpass.htm">l o s t  p a s s w o r d</a> | <a href="terms.htm">t o a</a> ] -<br>
<br>- v e r s i o n [ 0.01 ] -
</form>
<br><br>
<br><br>
<a href="main.php">- b y p a s s - l o g i n -</a>
</center>
</body>
</html>
__________________
trevor is offline   Reply With Quote
Old 01-16-2003, 07:27 PM   #14 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
what about connect.php?


Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-16-2003, 07:28 PM   #15 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
Quote:
Originally posted by trevor


...I should probably read it If you already have it installed you can save 4 hours

Say What?

Yes, I am starting Chapter 7.

Ilya
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is a shell variable in UNIX Shell Script rakesh Linux 0 08-31-2004 08:25 AM
running a script at designated time tzarin PHP 5 05-12-2004 07:11 PM
Login With Sessions sde PHP 1 08-16-2003 03:20 PM
JS Script question M3GAPL3X HTML, XML, Javascript, AJAX 5 04-20-2003 09:21 PM
narrowed down login trouble trevor PHP 7 01-18-2003 05:50 PM


All times are GMT -8. The time now is 11:42 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle