473,396 Members | 1,859 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,396 software developers and data experts.

HTTP Authentication with multiple attempts

I have used the simple example of HTTP Authentication from the PHP website
as follows:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
My authentication code here
}
?>

At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five attempts
before being locked-out. I guess I need a counter so that I can
unset($_SERVER['PHP_AUTH_USER']; if there are any attempts remaining, but
I can't work out a way to make the counter persistent across attempts.

All ideas welcome.

--
Jul 17 '05 #1
5 3239
Sparkplug wrote:
At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five attempts
before being locked-out. I guess I need a counter so that I can


If you use HTTP basic authentication there is no way to influence it.
The webserver handles the authentication and that's about it. There are
no options for basic authentication (at least none I am aware of) in
Apache. It's a take it (and let the server handle it its way) or leave
it (and program you own authentication, which might be less secure,
buggy, prone to database manipulation, ...).

You do have 3 tries for basic authentication though. At least that's the
way Apache handles it, I don't know about other webservers.

Bye!
Jul 17 '05 #2
On Thu, 02 Dec 2004 16:26:06 +0100, Anonymous <an*******@nowhere.invalid>
wrote:
Sparkplug wrote:
At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five
attempts
before being locked-out. I guess I need a counter so that I can


If you use HTTP basic authentication there is no way to influence it.
The webserver handles the authentication and that's about it. There are
no options for basic authentication (at least none I am aware of) in
Apache. It's a take it (and let the server handle it its way) or leave
it (and program you own authentication, which might be less secure,
buggy, prone to database manipulation, ...).

You do have 3 tries for basic authentication though. At least that's the
way Apache handles it, I don't know about other webservers.


I'm running Apache on W2K for development and Linux for production and in
each case it only gives me one shot. Any more ideas?

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 17 '05 #3
"Sparkplug" <sp*******@nowhere.net> wrote in message
news:opsidypgpufps5jf@cblaptop...
I have used the simple example of HTTP Authentication from the PHP website
as follows:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
My authentication code here
}
?>

At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five attempts
before being locked-out. I guess I need a counter so that I can
unset($_SERVER['PHP_AUTH_USER']; if there are any attempts remaining, but
I can't work out a way to make the counter persistent across attempts.

All ideas welcome.


I don't see why the user would get locked out. HTTP is stateless. Each
request is independent of each other. IE does not bring up the
authentication dialog box again after three failed attempts. But it will do
so again if you refresh the page. Netscape on the other hand would keep
showing the dialog box as long as it's receiving the status code 401.

Perhaps the problem here is your code. Are you sending 401 when the
username/password pair is incorrect? The absence of the PHP_AUTH_USER
needn't really to be handled separately. No username/password is--for the
most part--the same as wrong username/password.

As for limiting the number of attempts, the only effectively way to do this
is to save the time of each attempt in a database or a file on the server,
then count the number of attempt within a given time period.
Jul 17 '05 #4
On Thu, 2 Dec 2004 20:32:46 -0500, Chung Leong <ch***********@hotmail.com>
wrote:
"Sparkplug" <sp*******@nowhere.net> wrote in message
news:opsidypgpufps5jf@cblaptop...
I have used the simple example of HTTP Authentication from the PHP
website
as follows:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
My authentication code here
}
?>

At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five
attempts
before being locked-out. I guess I need a counter so that I can
unset($_SERVER['PHP_AUTH_USER']; if there are any attempts remaining,
but
I can't work out a way to make the counter persistent across attempts.

All ideas welcome.


I don't see why the user would get locked out. HTTP is stateless. Each
request is independent of each other. IE does not bring up the
authentication dialog box again after three failed attempts. But it will
do
so again if you refresh the page. Netscape on the other hand would keep
showing the dialog box as long as it's receiving the status code 401.

Perhaps the problem here is your code. Are you sending 401 when the
username/password pair is incorrect? The absence of the PHP_AUTH_USER
needn't really to be handled separately. No username/password is--for the
most part--the same as wrong username/password.

As for limiting the number of attempts, the only effectively way to do
this
is to save the time of each attempt in a database or a file on the
server,
then count the number of attempt within a given time period.


Bingo! I wasn't sending the headers after an unsuccessful attempt. The
code should look like this:

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
My authentication code here
if ($AuthenticationFailed == true) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'You are not authorised to access this page.';
exit;
}
}
?>

Many thanks.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 17 '05 #5
Sparkplug <sp*******@nowhere.net> wrote in message news:<opsidypgpufps5jf@cblaptop>...
At the moment, if the user gets it wrong they are locked-out until they
restart their browser.However, I want the user to have, say, five attempts
before being locked-out. I guess I need a counter so that I can
unset($_SERVER['PHP_AUTH_USER']; if there are any attempts remaining, but
I can't work out a way to make the counter persistent across attempts.


The answer to the "persistent" question will always be: cookie or session
You could send a cookie with the 401 and check it..
Or use a session...
Jul 17 '05 #6

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
1
by: VJ | last post by:
Hi, IIS raises login dialog box prompt on browser for resources protected using basic authentication. That login prompt gives user 3 attempts to enter correct userid/password. IIS throw 401.1...
3
by: Raquel | last post by:
I am confused between Authentication at Instance Vs Authentication at Database. Instance authentication is specified at Instance creation time (db2icrt) and is stored in db mgr. cfg. file while...
5
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
3
by: Martin | last post by:
Dear fellow ASP.NET programmer, I stared using forms authentication and temporarily used a <credentials> tag in web.config. After I got it working I realized this wasn't really practical. I...
6
by: Frank Walsh | last post by:
Can anyone tell me if this is possible in asp.net, I want to use form-based authentication to authenticate my users, however a employee of the company is attempting to be logged in as administrator...
2
by: UJ | last post by:
I have a web site up and going and on the main login screen there's a help menu option. If the person selects that before they have logged in, it attempts to redirect them to a page telling them...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
6
by: thomson | last post by:
Hi All, i do hae a solution in which i do have mulitple projects including Web Projects,, Depending on the functionality it gets redirected to different web projects and it is working fine, ...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.