Adam. R

How to password PROTECT 🔒 your website using JAVASCRIPT!

Created November 1, 2021

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

<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=""; 

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

Live Demo (Thanks to AWS Amplify): The password is pass1.

Also here is a video demo.