Basic Password Gate

A simple way to restrict access. This script prompts the user for a password immediately upon page load. If they enter the correct string, they stay; otherwise, they are redirected.

The correct password is: magic

Copy the Script

<script>
var pass = prompt("Please enter the password:");
if (pass != "magic") {
    alert("Incorrect password!");
    history.back(); // Send them back
    // OR: window.location = "index.html";
}
</script>

Frequently Asked Questions

No. The password is visible in the page source code. Anyone who knows how to 'View Source' can find it. This is only for very basic 'casual' protection (e.g., a family quiz page).

The script typically redirects them to the previous page using 'history.back()' or alerts them to try again.

Yes. You can use an 'OR' operator in the if-statement (e.g., pass == '123' || pass == 'ABC').