How to password PROTECT 🔒 your website using JAVASCRIPT!

How to password PROTECT 🔒 your website using JAVASCRIPT!

Written by Adam. R on Nov 1st, 2021 Views Report Post

Table of contents

These scripts are very simple javascript. They are the first line to protect privacy of webpages. Someone who can access the HTML page source code can easily find the username and password and enter the page. Anyone with a little idea about HTML and computers can see the source code.


The Script

The javascript displays a form to enter the Username and Password. If either is wrong, it will display and alert screen like ‘Wrong Username’ or ‘Wrong Password’.

The username is set to ‘SECRET_USER‘ and the password is ‘SECRET_PASSWORD‘ – both can be set as you like. If both are right, then you are taken to the next URL, which is currently set to this YOURDOMAIN.com.

<SCRIPT language="JavaScript">
var password; 
var pass1="SECRET_PASSWORD"; 
password=prompt('Enter Password',' '); 
if (password==pass1) 
alert('Correct Password! Click OK to Enter!'); 
else { window.location="http://YOURDOMAIN.com/"; 
} 
</SCRIPT>

To change the password change look at line 4 and change pass1 to whatever password!

Live Demo (Thanks to AWS Amplify): https://master.d37ksplxa972bh.amplifyapp.com The password is pass1.

Also here is a video demo.

Comments (0)