disble th usr fr5 mi whn he inputs th wrng pwd 1 tme usg php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

annrose
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Sep 26, 2012 7:03 pm

disble th usr fr5 mi whn he inputs th wrng pwd 1 tme usg php

Postby annrose » Wed Sep 26, 2012 7:15 pm

Code: Select all

how to disable the user  for 5 minut when he inputs the wrong pwd in only on time using php?
iam trying but iam note access login page pls help...
<?php session_start();?>
<?php error_reporting(E_ALL ^ E_NOTICE);//hiding error using?>
      <?php
    require("connect.php");
    $myusername=$_POST['username'];
    $mypassword=$_POST['password'];
    // let's say the block time is 5 mins
    $failded_waiting_time = 300; // 5 mins
    if(!isset($_SESSION['login_counter'])) $_SESSION['login_counter']=0;
    if($_SESSION['login_counter'] = 1)
   {
       $period = time()-$_SESSION['failed_login'];
    if($period < 500) {
    // do wat you want here like saying u need to wait
    // rediorect to login page
    header("location:head.php");
    }
    // if period > $failded_waiting_time
    // reset time
    $_SESSION['failed_login'] = time();
    }
   $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

    if(isset($_POST['sub']))
    {
   if (empty($myusername) || empty($mypassword))
    {
        $problem = TRUE;
    }
   
   
   
    $sql="SELECT * FROM login WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
   
    if($count==1)
    {
    $_SESSION['myusername'] = $myusername;
   $_SESSION['mypassword'] = $mypassword;
   
    header("location:page.php");
   exit;
    }
    else
    {
    $_SESSION['login_counter']=$_SESSION['login_counter']+1;
    // register the 1 failed acces time
    if($_SESSION['login_counter'] == 1) {
    $_SESSION['failed_login'] = time();
    }
    header("location:index.php");
    }
   }
   
    ?>
   <html>
   <head>
   </head>
   <body>
<form method="post" action="login.php">
<table border="2">
<tr><td>userName</td><td><input type="text" name="username"/></td></tr>
<tr><td>Password</td><td><input type="password" name="password"/></td></tr>
<tr><td><input type="submit" name="sub" value="Login"></td></tr>

</table>

</form>
</body>

</html>


Return to “PHP coding => General”

Who is online

Users browsing this forum: kstartl83 and 2 guests