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

how to have a login attempts after 3invalid password cant login for 5minutes?

I would like to make this code to have a login attempts after 3 invalid input the user will be ban for logging-in in 5minutes then after the given time the user may login again.. how do i set a time? and is my code correct?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title>LOG IN</title>
  5. </head>
  6. <?php
  7. session_start();
  8. $username = (@$_POST['username']);
  9. $password = (@$_POST['password']);
  10. $attempts = ($_POST ['attempts']);
  11.  
  12. $error['alert'] = '';
  13. $error['username'] = '';
  14. $error['password'] = '';
  15. $input['username'] = '';
  16. $input['password'] = '';
  17.  
  18.  
  19.  
  20. if (isset($_POST['submit'])) 
  21. {
  22.     if ($_POST['username'] == '' || $_POST['password'] == '') 
  23.     {
  24.  
  25.  
  26.  
  27.         if ($_POST['username'] == '') { 
  28.             $error['username'] = 'required'; }
  29.         if ($_POST['password'] == '') { 
  30.             $error['password'] = 'required'; }    
  31.         $error['alert'] = 'Please fill in required fields!';
  32.  
  33.          $_POST['username'];
  34.          $_POST['password'];
  35.  
  36.         include('v_login.php');
  37.  
  38.  
  39.         if($username!=$dbusername&& md5($password)!=$dbpassword)
  40.          {
  41.           $connect = mysql_connect("mysql1.000webhost.com","a4063609_renz","ny4n93");
  42.                   mysql_select_db("a4063609_phplogi") or die ("Couldn't find db");
  43.  
  44.  
  45.             // Increment login count... 
  46.             mysql_query("UPDATE users SET attempts = attempts + 1 WHERE username = '$username'"); 
  47.  
  48.          // Fetch login count... 
  49.             $result = mysql_query("SELECT attempts WHERE username = '$username'"); 
  50.             $attempts = mysql_result($result);
  51.  
  52.          if($attempts >= 3) 
  53.            { 
  54.           echo "Please Wait!"; 
  55.              }  
  56.  
  57.          }
  58.  
  59.     }
  60.     else
  61.     $error['alert'] = "Username or Password is incorrect";
  62.     {
  63.  
  64.     if ($username&&$password)
  65.     {
  66.          $connect = mysql_connect("mysql1.000webhost.com","a4063609_renz","ny4n93");
  67.                   mysql_select_db("a4063609_phplogi") or die ("Couldn't find db");
  68.  
  69.     $query = mysql_query("SELECT * FROM users WHERE username='$username'");
  70.  
  71.  
  72.     $numrows= mysql_num_rows($query);
  73.  
  74.         if($numrows!==0)
  75.         {
  76.         while($row=mysql_fetch_assoc($query))
  77. {
  78. $dbusername= $row['username'];
  79. $dbpassword= $row['password'];
  80. $activated= $row['activated'];
  81.  
  82. if($activated=='0')
  83. {
  84.      header("location:not_active.php");
  85.      exit();
  86. }
  87.  
  88.  
  89. }
  90. if($username==$dbusername&& md5($password)==$dbpassword)
  91. {
  92.       mysql_query("UPDATE Users SET $attempts = 0 WHERE $username = 'username'"); 
  93.  
  94.     header("location:member.php");
  95.     $_SESSION['username']=$username;
  96.  
  97. }
  98. else
  99. $error['alert'] = "Username or Password is incorrect";
  100. include('v_login.php');
  101.         }
  102.     else
  103.         {
  104.         $error['alert'] = "Username or Password is incorrect";
  105.         include('v_login.php');
  106.         }
  107.  
  108.  
  109.     }
  110.     else
  111.     {
  112.         echo "";
  113.     }    
  114.  
  115.     }
  116.  
  117.  
  118. }
  119.  
  120. else
  121. {
  122.  
  123.     include('v_login.php');
  124. }
  125.  
  126.  
  127. ?>
  128.  
  129. </html>
  130.  
  131.  
  132.  
I
Oct 10 '12 #1
3 14873
johny10151981
1,059 1GB
First thing is why do you need to ask this question in two questions?

Secondly you can use session to save login attempt count with time limit. if in a short time duration user try to attempt log in for 3 times then you can set a variable in user database that would say locked, also there will have to be another variable that would describe when the locking started. simple example:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $var=try_log_in();
  3. if($var===false)
  4. {
  5.  if(isset($_SESSION['LogInAttempt'])==true && is_numeric($_SESSION['LogInAttempt'])==true && isset($_SESSION['FirstLogInAttemptTime'])==true && $_SESSION['FirstLogInAttemptTime']-time()<$certainTime)
  6. {
  7.  $_SESSION['LogInAttempt']++;
  8.  if($_SESSION['LogInAttempt']==3)
  9.   {
  10.    the_function_to_lock_the_user();
  11.   }
  12. }
  13. else
  14. {
  15.  $_SESSION['LogInAttempt']=1;
  16.  $_SESSION['FirstLogInAttemptTime']=time(); 
  17. }
  18.  exit("With proper and nicely mannered comment");
  19. }
  20. ?>
  21.  
Oct 10 '12 #2
thank you for your answer. But what is the function to lock the user? sorry I'm still a beginner sir do I still need to make another php file for that and include it to my login form or what? sorry sir and thank you
Oct 10 '12 #3
johny10151981
1,059 1GB
create one more column in your user table. name it lockckingtime or whatever that make sense, with the type timestamp . when third attempt fail sime set the current time. and in next login attempt check the difference between saved time and current time and lockcking time
Oct 11 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sam | last post by:
HI, I installed php4 for apached and restart apache afterward. but my little php script generated error followint error: PHP Notice: Undefined index: myname in...
1
by: tchangmian | last post by:
Hi all, If the user had log in with correct user id but wrong password, i would like to capture the time when the user fail to login for the 1st time. Within 24 hours, if the user had tried to...
0
by: =?Utf-8?B?Q2hpV2hpdGVTb3g=?= | last post by:
Hi, i got machine A that has sql2005, vs2005 project. project runs okay there. But when i copied that whole project folder to machine B, running sql2005, VS2005, edited the web.config file to...
18
by: icesh | last post by:
hi i'm a newbie in php.. can you help me how to make several login attempt in php? (if we put wrong password/username,, we will go back to the previous form and we can try 3 more attempts to input...
1
by: aradhanathawait | last post by:
Hi all Please tell me the default Login Id and password for Tomcat5.0 Admin. I have installed tomcat5 on Red hat linux 4, it didn't ask for admin password during installlation. Thanx and...
0
by: selvamariappan | last post by:
Hi all, How to find login name and password for sqlserver 2005 in sql server authentication mode, In my sys i have installed .net and then i have installed sqlserver express, i want...
1
by: Punkis | last post by:
Hello all. I am having some questions about a subject. I am running a small social community using SocialEngine and i want to include phpbb3 with an arcade mod or any arcade board that support high...
1
by: dharmbhav | last post by:
Hi, I am designing a login mechanism for a website. Presently, I am blocking the user account for 1 hour if there are 3 failed login attempts with-in 1 hour. However, I want to know if there is...
4
by: imranshaiks786 | last post by:
I lost my administrator password and there is no other users to login. How can I still login to my system?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
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,...

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.