Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created November 2, 2015 08:02
Show Gist options
  • Save Archie22is/bb4bb0dc166040b87461 to your computer and use it in GitHub Desktop.
Save Archie22is/bb4bb0dc166040b87461 to your computer and use it in GitHub Desktop.
Simple jQquery require password to view resource / web page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Login Sample | https://github.com/Archie22is</title>
</head>
<body>
<input type="password" id="pass"> <input type="button" id="b" value="Login"><br>
<span id="err"></span>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
jQuery( document ).ready(function($) {
$("#b").click(function() {
var password = "password";
if($("#pass").val() !== password) {
$("#err").text("Incorrect password");
}
else {
$("#err").text("Password correct! Do whatever you need to do here.");
}
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment