/    Sign up×
Community /Pin to ProfileBookmark

Login failure when you try 3 times

Hi I ‘ve made a login prompt in php but know what I want to do is when you login 3 times with an invalid login the prompt doesnt come up. I’m new to php
heres my code

<?
if(!isset($PHP_AUTH_USER))
{
header(‘WWW-Authenticate: Basic realm=”Zona Restringida”‘);
header(‘HTTP/1.0 401 Unauthorized’);
echo “Zona Restringida:se requiere autorizacion.”;
exit();
}
else if(($PHP_AUTH_USER != ‘pepito’)||($PHP_AUTH_PW != ‘piscinas’))
{
header(‘WWW-Authenticate: Basic realm=”Zona Restringida”‘);
header(‘HTTP/1.0 401 Unauthorized’);
echo “Zona Restringida:se requiere autorizacion.”;
exit();
}
else
{
$nombre=strtoupper($PHP_AUTH_USER);
$pass=md5($PHP_AUTH_PW);
echo ‘Bienvenido’.$nombre.'<br/>Tu contraseña encriptada es:’.$pass;
}
?>

Thanks and cheers

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@STREETRULEZJul 09.2009 — [code=php]
<?
session_start(); // here goes the session
if(!$_SESSION['wrong_pass_count'])
$_SESSION['wrong_pass_count'] = 0;
if($_SESSION['wrong_pass_count'] >= 3)
die('Authorisation Failed!');

if(!isset($PHP_AUTH_USER))
{
header('WWW-Authenticate: Basic realm="Zona Restringida"');
header('HTTP/1.0 401 Unauthorized');
echo "Zona Restringida:se requiere autorizacion.";
exit();
}
else if(($PHP_AUTH_USER != 'pepito')||($PHP_AUTH_PW != 'piscinas'))
{
$_SESSION['wrong_pass_count'] += 1;
header('WWW-Authenticate: Basic realm="Zona Restringida"');
header('HTTP/1.0 401 Unauthorized');
echo "Zona Restringida:se requiere autorizacion.";
exit();
}
else
{
$nombre=strtoupper($PHP_AUTH_USER);
$pass=md5($PHP_AUTH_PW);
echo 'Bienvenido'.$nombre.'<br/>Tu contraseña encriptada es:'.$pass;
}
?>
[/code]



=)
Copy linkTweet thisAlerts:
@bokehJul 09.2009 — Dude, I know all the servers in Spain are configured way out of date, but, you need to read up on "register globals".

Maybe you could do it as follows:[code=php]<?php

if(!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm="Zona Restringida"');
header('HTTP/1.0 401 Unauthorized');
echo "Zona Restringida:se requiere autorizacion.";
exit();
}

if(($_SERVER['PHP_AUTH_USER'] != 'pepito')||($_SERVER['PHP_AUTH_PW'] != 'piscinas'))
{
setcookie('tries', @++$_COOKIE['tries']);
if($_COOKIE['tries'] > 4)
{
die();
}
header('WWW-Authenticate: Basic realm="Zona Restringida"');
header('HTTP/1.0 401 Unauthorized');
echo "Zona Restringida:se requiere autorizacion.";
exit();
}

$nombre=strtoupper($_SERVER['PHP_AUTH_USER']);
$pass=md5($_SERVER['PHP_AUTH_PW']);
echo 'Bienvenido'.$nombre.'<br/>Tu contrase&#241;a encriptada es:'.$pass;

?>[/code]
×

Success!

Help @rncommando spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...