How To Create Login Security Using JavaScript
Submitted by alpha_luna on Monday, April 25, 2016 - 14:57.
In this article, we are going to learn on How To Create Login Security Using JavaScript. This source code will protect your websites, systems, or any program that you have right now from a trespasser, stranger, and unauthorized users or a visitors.
This code contains If Statement in JavaScript, HTML Form Field, and CSS for the style.
Username: sourcecodester
Password: tutorial
JavaScript Source Code
This script will check the username and password input by the user then the If Statement will execute.
HTML Source Code
This HTML code contains the username and password textbox where the user typing the correct information to log in.
And, this is the style.
Output:
If the user inputs wrong details to the textbox.
If the user inputs correct details to the textbox.
So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.
- <script>
- function password_checking(form) {
- if (form.user_name.value=="sourcecodester") {
- if (form.password.value=="tutorial") {
- alert("Welcome to the system");
- }
- else {
- alert("Wrong Password. Please Try Again !!!");
- document.getElementById("username").focus();
- }
- } else {
- alert("Wrong Username. Please Try Again ");
- document.getElementById("username").focus();
- }
- }
- function reset_all()
- {
- document.getElementById("username").value=""
- document.getElementById("password").value=""
- document.getElementById("username").focus();
- }
- </script>
- <form class="form_style">
- <table border="0" width="100%" cellpadding="3" cellspacing="3">
- <tr class="tr_header">
- </tr>
- <tr bgcolor="azure">
- <td class="text_label">
- Username
- </td>
- <td style="text-align: center;">
- <input type="text" name="user_name" class="textBox_style" placeholder="Username....." id="username" autofocus>
- </td>
- </tr>
- <tr bgcolor="azure">
- </tr>
- <tr bgcolor="azure">
- <td class="text_label">
- Password
- </td>
- <td style="text-align: center;">
- <input type="password" name="password" class="textBox_style" placeholder="Password....." id="password">
- </td>
- </tr>
- <tr bgcolor="maroon">
- <td height="35" colspan="2" style="text-align: center;">
- <input type="submit" value="Log In" class="btn_login" onClick="password_checking(this.form)">
- <input type="button" value="Clear" class="btn_reset" onclick="javascript:reset_all();">
- </td>
- </tr>
- </table>
- </form>
- body {
- width:400px;
- margin:auto;
- }
- .tr_header {
- background: maroon;
- color: white;
- font-size: xx-large;
- text-align: center;
- }
- .text_label {
- text-align: center;
- font-size: 18px;
- color: blue;
- font-weight: bold;
- font-family: cursive;
- }
- .form_style {
- margin-top:100px;
- }
- .btn_login {
- width: 100px;
- font-size: 18px;
- color: blue;
- background: azure;
- border: blue 1px solid;
- border-radius: 4px;
- padding: 5px;
- cursor:pointer;
- margin-right:20px;
- }
- .btn_reset {
- width: 100px;
- font-size: 18px;
- color: maroon;
- background: azure;
- border: maroon 1px solid;
- border-radius: 4px;
- padding: 5px;
- cursor:pointer;
- }
- .textBox_style {
- font-size: 18px;
- text-indent: 5px;
- border: blue 1px solid;
- }
Add new comment
- 97 views