Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Login Form With Limited Login Attempts Using JavaScript And HTML

Saturday, Jan 21, 2017

Tags:- JavaScript HTML


Websites Like facebook uses login form with limited login attempts in this there is certain number of login attempts if you lost all the attempts then you have to login after some time.This method is used to increase login form security and prevent spamming on website.In this tutorial we will show you how to create login form with limited login attempts using JavaScript and HTML.You may also like login form with shake animation effect.


See Demo
Login Form With Limited Login Attempts


To Create Login Form With Login Attempts It Takes Only Two Steps:-

  1. Make a HTML file and define markup and scripting
  2. Make a CSS file and define styling


Step 1.Make a HTML file and define markup and scripting

We make a HTML file and save it with a name login.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="login_style.css">
<script type="text/javascript">
var login_attempts=3;
function check_form()
{
 var name=document.getElementById("name").value;
 var pass=document.getElementById("pass").value;
 if(name=="talkerscode" && pass=="talkerscode")
 {
  alert("SuccessFully Logged In");
  document.getElementById("name").value="";
  document.getElementById("pass").value="";
 }
 else
 {
  if(login_attempts==0)
  {
   alert("No Login Attempts Available");
  }
  else
  {
   login_attempts=login_attempts-1;
   alert("Login Failed Now Only "+login_attempts+" Login Attempts Available");
   if(login_attempts==0)
   {
    document.getElementById("name").disabled=true;
    document.getElementById("pass").disabled=true;
    document.getElementById("form1").disabled=true;
   }
  }
 }
 
 return false;
}	
</script>
</head>
<body>
<div id="wrapper">

<form id="form1" method="post" action="" onsubmit="return check_form();">
 <p id="login_label">USER LOGIN</p>
 <input type="text" id="name" placeholder="Enter Username">
 <br>
 <input type="password" id="pass" placeholder="Enter Password">
 <br>
 <input type="submit" value="SUBMIT FORM">
 <p>Username : talkerscode Password : talkerscode</p>
 <br>
</form>

</div>
</body>
</html>

In this step we create a form to do login with predefined username and password.We create a 'login_attempts' variable and set the value to 3 it means user have only 3 login attempts we also create check_form function under this we get username and password value and check if it matches our prefined name and password.If username and password does not match we decrement the attempt by 1 every time and if the attempt value reaches to 0 we disable form and form fields to prevent user for further login.You may also like flip animated login and signup form.



Step 2.Make a CSS file and define styling

We make a CSS file and save it with a name login_style.css

body
{
 text-align:center;
 width:100%;
 margin:0 auto;
 padding:0px;
 font-family:helvetica;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:995px;
}
#form1
{
 background-color:white;
 width:380px;
 margin-left:305px;
 box-shadow:0px 0px 10px 0px #D8D8D8;
}
#form1 p
{
 color:#FA8258;
 font-weight:bold;
}
#form1 #login_label
{
 color:#FA8258;
 padding:20px;
 font-size:25px;
 border-bottom:1px solid #E6E6E6;
 font-weight:bold;
}
#form1 input[type="text"],input[type="password"]
{
 width:300px;
 height:40px;
 padding-left:10px;
 margin-top:10px;
 border:1px solid #D8D8D8;
}
#form1 input[type="submit"]
{
 margin-top:10px;
 width:300px;
 height:40px;
 background-color:#FA8258;
 border:none;
 color:white;
 box-shadow:0px 3px 0px 0px #FE642E;
 border-radius:3px;
 font-weight:bold;
}

Thats all, this is how to create login form with limited login attempts using JavaScript and HTML.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH