Last active
August 28, 2018 18:28
-
-
Save sskylar/7b6ee7c36158a79a3316 to your computer and use it in GitHub Desktop.
Simple password protection using a md5 hashed slug in Siteleaf (note: this is not intended for high security, only to stop casual visitors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<input id="password" type="password"/> | |
<button>Submit</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uses https://code.google.com/p/crypto-js/ | |
$("form").submit(function(e) { | |
// recreate hashed slug | |
var hashed_slug = CryptoJS.MD5($('#password').val()); | |
// attempt to load in contents | |
$("body").load("/clients/"+hashed_slug, function(response, status, xhr) { | |
// if password was entered incorrectly this will be a 404 | |
if (status == "error") alert("Incorrect password"); | |
}); | |
e.preventDefault(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
permalink: "/clients/5ebe2294ecd0e0f08eab7690d2a6ee69/" | |
sitemap: false | |
--- | |
You correctly guesed the password: "secret" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use a tool like this to generate md5 hashes: http://www.miraclesalad.com/webtools/md5.php
e.g.
secret
becomes5ebe2294ecd0e0f08eab7690d2a6ee69