# Q14

#### Implement a static password protection.

{% hint style="info" %}
Stored password **statically** in script as **Javascript** code and validating it by picking password id and **Alert Box**

[Browse Source Code](https://github.com/MJK618/InternetTechnologies/blob/main/JAVASCRIPT/javascript_2.html)
{% endhint %}

### Code

{% tabs %}
{% tab title="javascript\_2.html" %}

```markup
<html>
<head>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
    <title>Password Security (pass=staticpass) 
    | Javascript 2 </title>
    <script>

        function pass() {   
            var password;
            var staticPassword="staticpass";

            password=(document.getElementById("pass").value);
            
            if (password==staticPassword)
                alert("Password Correct!");
            else
               alert('Password Incorrect!');    
       }

   </script>
</head>

<body>
<div class="container-fluid ">
    <center>
        
        <div class="container mt-5">
            <h1>Password Security (pass=staticpass) 
            | Javascript 2 </h1>
        </div>
      </center> 
    
    <div class="form-group mt-5">
        <div class="container mt-2">
   <label for="email">Enter Email</label>  
        </div>
        <div class="container mt-2">
            <input class="form=control w-75 p-3" 
            type="email" id="email" 
            placeholder="name@example.com" required>
        </div><div class="container mt-2">
        <label for="pass"> Enter Password</label> 
        </div>
        <div class="container mt-2">
            <input type="password" 
            class="form-control w-75 p-3" 
            id="pass" 
            placeholder="Enter Password = staticpass" 
            required>
        </div>
        <div class="container mt-2">
            <button class="btn btn-primary" 
            onclick="pass()">
                <a>Submit</a>
            </button>
        </div>
        </div>
    </div>
    </div>
</body>
</html>
```

{% file src="<https://1856586971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYBDzNEDANjFDzIvzi2%2F-MZY5aefzWGBCE69fb9U%2F-MZYFa2iyAv9yTmX7-JJ%2Fjavascript_2.html?alt=media&token=d120ee0a-8257-4d7b-85cf-4d1ff9be37f1>" %}
Download javascript\_2.html
{% endfile %}
{% endtab %}
{% endtabs %}

### Output

![Main Page (1/3)](https://1856586971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYBDzNEDANjFDzIvzi2%2F-MZY5aefzWGBCE69fb9U%2F-MZYFmvPKM_wA9VPbRYx%2Fimage.png?alt=media\&token=0ff9646a-a9d6-4d61-82b9-0878747ab595)

![Entering Wrong Password (2/3)](https://1856586971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYBDzNEDANjFDzIvzi2%2F-MZY5aefzWGBCE69fb9U%2F-MZYFujXwtY8CIOgirB5%2Fimage.png?alt=media\&token=05628f2e-4a66-4927-bb8d-d535d839311e)

![Entered Corrected Password (3/3)](https://1856586971-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYBDzNEDANjFDzIvzi2%2F-MZY5aefzWGBCE69fb9U%2F-MZYG10XrO7gMLI6NUmH%2Fimage.png?alt=media\&token=bc67fa8f-e3bb-4ab0-a867-29f6f313b66f)

{% hint style="success" %}
Try or Test The Corresponding Code Here
{% endhint %}

{% embed url="<https://codepen.io/MJK618/pen/oNBrYzR>" %}
Live Demo javascript\_2.html
{% endembed %}
