473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Does this Auth script have an unwanted loop?

Found the below script in a book I am reading.

However it seems to me to fatal flaw that if you run it but type in the
wrong the details, you're basically buggered. As far as I can see, whatever
is initially entered into PHP_AUTH_USER and PHP_AUTH_PW are stored and then
compared against the database. However #10 simply looks for the presence of
data in PHP_AUTH_USER and PHP_AUTH_PW, finds something and compares it
again in a loop you cannot break out of.

Can someone confirm what I am saying or have I missed something obvious.

Cheers

Phil
<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/

//Testing whether the user has been prompted for a user name
if (!isset($_SERVER['PHP_AUTH_USER'])) #10
{
header('WWW-Authenticate: Basic realm="secret section"');
header('HTTP/1.0 401 Unauthorized'); #13
exit("This page requires authentication!"); #14
} #15

// Testing the user name and password entered by the user
else
#18
{
include("Vars.inc");
#20
$user_name = trim($_SERVER['PHP_AUTH_USER']);
#21
$user_password= trim($_SERVER['PHP_AUTH_PW']);
$connection = mysqli_connect($host, $user, $passwd) or die("Couldn't
connect to server."); #24
$db = mysqli_select_db($connection, $database) or
die("Couldn't select database.");
$sql =
"SELECT user_name FROM Valid_User WHERE user_name = '$user_name' AND
password = md5('$user_password')";
$result = mysqli_query($connection, $sql) or die("Couldn't execute
query."); #31
$num = mysqli_num_rows($result);
#32

if ($num < 1) // user name/password not found #33
{
exit("The User Name or password you entered is not valid.<br>");
} #37
} #38
// Web page content. #39
include ("Welcome.inc"); #40
?>
Nov 1 '06 #1
1 1076


On Nov 1, 9:09 pm, "Phil Latio" <phil.la...@f-in-stupid.co.ukwrote:
Found the below script in a book I am reading.

However it seems to me to fatal flaw that if you run it but type in the
wrong the details, you're basically buggered. As far as I can see, whatever
is initially entered into PHP_AUTH_USER and PHP_AUTH_PW are stored and then
compared against the database. However #10 simply looks for the presence of
data in PHP_AUTH_USER and PHP_AUTH_PW, finds something and compares it
again in a loop you cannot break out of.

Can someone confirm what I am saying or have I missed something obvious.
Looks you are right. Please consider the examples on
http://www.zend.com/zend/tut/authent...authentication
When user provided wrong credentials, the 401 error should be sent
again.

Sincerely,
Alexander
http://www.alexatnet.com/ - PHP/ZendFramework/Ajax blog

Nov 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
6
by: Ray | last post by:
DB2 V7.2 Is it possible to list applications connected to a node by Auth ID? Is it possible to force applications connected to a node by Auth ID or am I forced to use App. Handle? Thanks, Ray
3
by: Justin Dutoit | last post by:
Hey. I have the error CS0117 'BusinessLayer' does not contain a definition for 'MySoapHeader'. Below is a link to the asmx source, and the code which calls the web service. MS seems to do the same...
1
by: Toble Rone | last post by:
I now that this can be a completely newbie question, but and a bit confused on this. I currently in a new project where i need to expose a lot of "sql functionality" to users using a WinForms...
16
by: lovecreatesbeauty | last post by:
/* When should we worry about the unwanted chars in input stream? Can we predicate this kind of behavior and prevent it before debugging and testing? What's the guideline for dealing with it? ...
0
by: kevin bailey | last post by:
I have a framework working where I have multiple pages each checking the authentication status. Unauthorised users are redirected to a login page - otherwise the requested page is shown. ...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
1
by: kevin bailey | last post by:
I have used the PEAR Auth package to successfully set up authentication. <code> // Details of where the authentication details are stored. $options = array( 'dsn'...
4
by: J. Frank Parnell | last post by:
The goal here is to use basic authentication for a user to log in, but keep a cookie so that they dont have to log in every browser session. <? $user = "user"; $pass = "pass"; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.