Jump to content

Recommended Posts

My problem is to get the counter to work for x failed logins.

My columns in MySQL are: id, username, password, attempts & adress!

 

 

if ($result[0]['total'] == true)
{

$_SESSION['userLogin'] = $result[0]['total'];
$_SESSION['isLoggedIn'] = $login;
header('location: index.php?id=home');
$db->query("UPDATE authenticate SET attempts=0, adress='$ip' WHERE username='$login'");
exit;
}
else
{
$rs = mysql_query('SELECT id,username,password,attempts,address FROM authenticate WHERE username = '.$username.'');
$num = mysql_num_rows($rs);
if ($row['attempts'] > 3) {
	// Redirect to captcha
	header('location: captcha.php');
} else {
	$ip = $_SERVER['REMOTE_ADDR'];
	if ($row['address'] != $ip) {
	// New ip adress, reset failed logins
	$failed_logins = 0;
	} else {
	// Increment failed logins
	$failed_logins = $row['attempts']+1;
	}
	mysql_query('UPDATE authenticate SET attempts = '.$failed_logins.',address = '.$ip.' WHERE id = '.$row['id'].' ');
}
header('location: index.php');
exit;
}

Link to comment
https://forums.phpfreaks.com/topic/274287-after-x-failed-attempts/
Share on other sites

You can't just expect us to look at this and figure out what your problem is. You've made it apparent that you want to show a captcha after 3 failed login attempts, but it would make things move smoother for everyone if you pointed out what is or is not doing correctly?

They told me to debug, but how ^^

Well first off, where is this $row variable created? Not to mention $result[0]...

You ask for help with debugging yet you do not provide all the relevant code. That's like taking out your car's alternator.. bringing it to the mechanic and saying "My car just won't start.. why not?"

Here's some resources to learn how to debug your PHP scripts:

 

First off I recommend this article on basic debugging principles, as well this thread on StackOverflow that lists a lot of IDEs and debuggers (along with links on how to set them up).

 

Once you've read those, there's a lot of hits on Google, for more detailed and/or advanced debugging techniques.

Well first off, where is this $row variable created? Not to mention $result[0]...

You ask for help with debugging yet you do not provide all the relevant code. That's like taking out your car's alternator.. bringing it to the mechanic and saying "My car just won't start.. why not?"

 

Tell me if i should change the concept or keep on writing on this one...

Here is my full code:

 

<?php
require_once 'libs/config.php';

ini_set('display_errors', 'On'); error_reporting(E_ALL);

$login = @mysql_real_escape_string(trim($_POST['username']));
$password = @mysql_real_escape_string(trim(sha1($_POST['password'])));

$db->query("
SELECT COUNT(id) AS total, username
FROM authenticate
WHERE username = '$login'
AND password = '$password' LIMIT 1
");
$result = $db->get();


if ($result[0]['total'] == true)
{

 $_SESSION['userLogin'] = $result[0]['total'];
 $_SESSION['isLoggedIn'] = $login;
 header('location: index.php?id=home');
 $db->query("UPDATE authenticate SET attempts=0, adress='$ip' WHERE username='$login'");
 exit;
}
else
{
 $rs = mysql_query('SELECT id,username,password,attempts,address FROM authenticate WHERE username = '.$username.'');
 $num = mysql_num_rows($rs);
 if ($row['attempts'] > 3) {
		 // Redirect to captcha
		 header('location: captcha.php');
 } else {
		 $ip = $_SERVER['REMOTE_ADDR'];
		 if ($row['address'] != $ip) {
		 // New ip adress, reset failed logins
		 $failed_logins = 0;
		 } else {
		 // Increment failed logins
		 $failed_logins = $row['attempts']+1;
		 }
		 mysql_query('UPDATE authenticate SET attempts = '.$failed_logins.',address = '.$ip.' WHERE id = '.$row['id'].' ');
 }
header('location: index.php');
exit;
}

Edited by lunkn
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.