How To Limit The Number Of Login Attempts

How to limit the number of login attempts  image

Let's create a login form page a user can login.

<form  class="modal-contentloginform" id="table" method="post" action="<?php echo BASE_URL . 'login.php'; ?>"  onSubmit = "return validate()">         
	 <div class="header_login">
	 <?php include(ROOT_PATH . '/includes/errors.php'); ?>
	  <?php include(ROOT_PATH . '/includes/messages.php'); ?>
	  <?php include(ROOT_PATH . '/includes/activatemessages.php'); ?>	
	<!--notification for logout -->
	<div id="notification">
	<?php 
	if (isset($_GET['logout'])) {
	?>
	<div id="notificationtimes" style="background-color:transparent;cursor:pointer;" onclick="document.getElementById('notification').style.display='none'"><i class="fas fa-times"></i>
	</div> 	
    <?php
    echo '<p class="message"><i class="fas fa-check-circle fa-2x"></i> You have successfully logged out from the system.</p>';
	}
	?>
	</div>
	<!--notification for like/dislike -->
	<div id="notification_likedislike">
	  <?php 
      if (isset($_GET['likedislike'])) {
      ?>
      <div id="notificationtimes" style="background-color:transparent;color:#a94442;cursor:pointer;" onclick="document.getElementById('notification_likedislike').style.display='none'"><i class="fas fa-times"></i>
     </div> 	
     <?php
     echo '<p class="errors" style="font-weight:normal;"><i class="fas fa-times-circle fa-2x"></i> You have to LogIn/Register to Like/Dislike a content.<br/>Thank You.</p>';
	}
	?>
	</div>
	<!--notification for download -->
	<div id="notification_download">
	    <?php 
      if (isset($_GET['download'])) {
      ?>
      <div id="notificationtimes" style="background-color:transparent;color:#a94442;cursor:pointer;" onclick="document.getElementById('notification_download').style.display='none'"><i class="fas fa-times"></i>
      </div> 	
       <?php
       echo '<p class="errors" style="font-weight:normal;"><i class="fas fa-times-circle fa-2x"></i> You have to LogIn/Register to Download a source code.<br/>Thank You.</p>';
    	}
    	?>
	</div>
	<h1><span  style="background:var(--clr-postbutton);padding:0 10px 0 10px;mix-blend-mode: screen;">LogIn</span></h1>
	</div>   
	<div class="container" style="background-color:rgba(44, 62, 80, 0.2);">
    <div class="row">
      <div class="vl">
        <span class="vl-innertext">OR</span>
      </div>
      <div class="col">
      <div class="input-container">
      <i class="fa fa-user icon"></i>
      <div class="label_wraps">
      <label for="email" id="loginname">Enter Email/Username</label>
      <input type="text" name="email" id="emaillogin" onkeyup="success()"/>
      </div>
      </div>
      <div class="email_avail_result" id="email_avail_result_login" style="margin-top-25px;"></div> 
     <div class="input-container">
	 <i class="fa fa-lock icon"></i>
	 <div class="label_wraps" style="width:auto;">
      <label for="password" id="loginpassword">Enter Password</label>
      </div>
	 <input  type="password"  name="password" id="passwordlogin" onkeyup="success()" />
	 <span  onclick="mypasswordshow()">
	 <i id="hide1" class="fas fa-eye eyes_show"></i>
	 <i id="hide2" class="fas fa-eye-slash eyes"></i>
	 </span>
	 </div>
	 <div id="display_text">Caps lock is ON.</div>
	 <div id="checkbox-container" style="float:right;">
     <input type="checkbox" style="font-size:18px;" name="remember" id="remember"/>Remember me
     </div>
	<button  class="cancel_btn login_cancel_btn btn-sep icon-cancel" type="reset" >Clear</button>
	<button  class="login_btn login_cancel_btn btn-sep icon-login" name="login_btn" id = "login_btn" type="submit" onclick=saveData("+lat+","+lng+") disabled>Login</button>
    </div>
    <div class="col">
        <div class="hide-md-lg">
          <h1><span class="vl-innertext1" style="color:var(--clr-darkcolor);font-size:18px;">OR</span></h1>
        </div>
    </div>
    <div class="col" style="margin-top:18px;">
        <a href="<?php echo BASE_URL . 'coming-soon';?>" class="fb btn_loginwith">
          <i class="fab fa-facebook-f fa-lg"></i> Login with Facebook
         </a>
        <a href="<?php echo BASE_URL . 'coming-soon';?>" class="tw btn_loginwith">
          <i class="fab fa-twitter fa-lg"></i> Login with Twitter
        </a>
        <a href="<?php echo BASE_URL . 'coming-soon';?>" class="gl btn_loginwith">
        <i class="fab fa-google fa-lg"></i> Login with Google
        </a>
        <a href="<?php echo BASE_URL . 'coming-soon';?>" class="lk btn_loginwith">
        <i class="fab fa-linkedin fa-lg"></i> Login with LinkedIn
        </a>
    </div>      
    </div>
</div>

<div class="bottom-container">
  <div class="row_button">
    <div class="col_button">
      <a href="<?php echo BASE_URL . 'password-recovery/enter_email';?>" id="submit_forget" class="btn_signup"><i class="fas fa-lock fa-fw"></i> Forgot Password?</a>
    </div>
    <div class="col_button">
      <a onclick="document.getElementById('id01').style.display='block'" id="submit_signup" class="btn_signup"><i class="fas fa-user-plus fa-fw"></i> Create an Account</a>
    </div>
  </div>
</div>
</form>

Output the above HTML interface design look like this after you implement all functionality

       

then include the following JavaScript function for CapsLock, disable login button if the field empty, and password hide and show

 
    var password_input = document.getElementById("passwordlogin");
    var display_text = document.getElementById("display_text");
    password_input.addEventListener("keyup", function(event) {
    if (event.getModifierState("CapsLock")) {
    display_text.style.display = "block";
  } else {
    display_text.style.display = "none"
  }
});
 
<?php 
    if(isset($_COOKIE["emaillogin"]) AND isset($_COOKIE["passwordlogin"])){
    $email = $_COOKIE["emaillogin"];
    $password = $_COOKIE["passwordlogin"];
    echo "
    document.getElementById('emaillogin').value = '$email';
    document.getElementById('passwordlogin').value = '$password';
    ";
    }
    if(isset($_COOKIE["remember"])){
    $remember = $_COOKIE["remember"];
    echo "
    document.getElementById('remember').value = '$remember';
    ";
    }
?>

function success() {
   var email_value = document.getElementById("emaillogin").value;
   var pass_value = document.getElementById("passwordlogin").value;
	 if(email_value.length<10 || pass_value.length<=7) { 
            document.getElementById('login_btn').disabled = true; 
        }
        else { 
            document.getElementById('login_btn').disabled = false;
            document.getElementById('login_btn').style.background = "var(--clr-postbutton)";
            document.getElementById('login_btn').style.color = "white";
            document.getElementById('login_btn').style.cursor = "pointer";
            document.getElementById("login_btn").onmouseover = function() 
           {
           this.style.backgroundColor = "var(--clr-sidemenulinkcolorhover)";
           this.style.color="black";
           this.style.opacity="0.6";
           }
           document.getElementById("login_btn").onmouseout = function() 
           {
           this.style.backgroundColor = "var(--clr-postbutton)";
           this.style.color = "white";
          this.style.opacity="1";         
           }
        }
    }

             function countDown(secs,elem) {
              var element = document.getElementById(elem);
              element.innerHTML = "* You have "+secs+" seconds left.";
                	if(secs < 1) {
                		clearTimeout(timer);
                		element.innerHTML = 'Times Up! You may now try login';
                	}
                	secs--;
                	var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);
                }
              countDown(60,"status");            
  
function mypasswordshow(){
	var x=document.getElementById("passwordlogin");
    var y=document.getElementById("hide1");
    var z=document.getElementById("hide2");
    if(x.type === 'password'){
		x.type="text";
		y.style.display="block";
	    z.style.display="none";
	}
	else {
		x.type="password";
		y.style.display="none";
	    z.style.display="block";
	}
}
var myInput = document.getElementById("passwordlogin"); 
myInput.onfocus = function() {
document.getElementById("passwordlogin").value="";
	 }

Leave a non public comment how to improve it.



Characters Remaining

We are sorry for your bad experiance. Leave a non public comment how to improve it.



Characters Remaining

Related Posts (12)

Getting User Device Location and Updating Database image

Getting User Device Location and Updating Database

Author image
By JOHN Mon Feb 19, 2024 at 12:31 PM (3 months ago)
Updated On Sat Mar 09, 2024 at 07:59 AM (2 months ago)

Read More »
How to create a custom archive page template on your website layout image

How to create a custom archive page template on your website layout

Author image
By JOHN Thu Nov 17, 2022 at 08:00 AM (2 years ago)
Updated On Thu Jan 05, 2023 at 06:24 PM (one year ago)

Read More »
Test the video layout design(Upload and Store video to MySQL Database with PHP) image

Test the video layout design(Upload and Store video to MySQL Database with PHP)

Author image
By JOHN Sat Nov 05, 2022 at 05:15 PM (2 years ago)
Updated On Wed Nov 09, 2022 at 06:39 PM (2 years ago)

Read More »
How to set the expiry period for a reset password link. image

How to set the expiry period for a reset password link.

Author image
By JOHN Mon Oct 10, 2022 at 05:31 AM (2 years ago)
Updated On Tue Nov 08, 2022 at 07:53 PM (2 years ago)

Read More »
Send A verification email when a new user registered  image

Send A verification email when a new user registered

Author image
By JOHN Tue Dec 07, 2021 at 04:53 PM (2 years ago)
Updated On Tue Nov 08, 2022 at 06:58 AM (2 years ago)

DGDFH

Read More »
How to Send Verification link when a new user register image

How to Send Verification link when a new user register

Author image
By JOHN Fri Oct 15, 2021 at 07:49 AM (3 years ago)
Updated On Fri Nov 04, 2022 at 05:00 PM (2 years ago)

This tutorial teaches you to build an email verification script from scratch

Read More »
How to limit the number of login attempt using PHP part 2(PHP functionality) image

How to limit the number of login attempt using PHP part 2(PHP functionality)

Author image
By JOHN Tue Sep 22, 2020 at 06:47 PM (4 years ago)
Updated On Wed Nov 09, 2022 at 05:06 PM (2 years ago)

To protect spam or junk email registration the system have to verify user email by sending a verification link to a  proven email address[] 

Read More »
Download file using PHP image

Download file using PHP

Author image
By MEWDED Wed Sep 02, 2020 at 10:04 AM (4 years ago)
Updated On Sat Nov 12, 2022 at 09:10 AM (2 years ago)

Short explanation 

Read More »
Inactive user enforce to login (SESSION expired) or Limmit the resource image

Inactive user enforce to login (SESSION expired) or Limmit the resource

Author image
By MEWDED Tue Sep 01, 2020 at 04:24 AM (4 years ago)
Updated On Sat Nov 12, 2022 at 09:35 AM (2 years ago)

Quick description

Read More »
How to count page viewers based on the IP Address of the device image

How to count page viewers based on the IP Address of the device

Author image
By MEWDED Thu Aug 27, 2020 at 04:37 PM (4 years ago)
Updated On Sat Nov 12, 2022 at 06:57 PM (2 years ago)

Hi, today we will walk you through how to implement to count the page viewers base on IP address like Youtube or Facebook 

Read More »
Pagination in PHP image

Pagination in PHP

Author image
By MEWDED Fri Aug 14, 2020 at 02:58 PM (4 years ago)
Updated On Fri Nov 04, 2022 at 03:08 PM (2 years ago)

Hi there ????, 

TODAY we are walking ????‍?? together to show you how to implement pagination in PHP

Read More »
Author Title image

Author Title

Author image
By JOHN Mon Jul 13, 2020 at 04:19 AM (4 years ago)
Updated On Fri Nov 04, 2022 at 03:08 PM (2 years ago)

Author description

Read More »

Share this on

Search


Archives

No archives data found yet in 2025.

No archives data found in 2016.

Find Us on Facebook

Subscribe for new updates




Back to Top