Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHA256, No jQuery, Robots.txt, Less HTML #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pages:
stage: deploy
script:
- mkdir .public
- cp -r * .public
- mv .public public
artifacts:
paths:
- public
only:
- master
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<i>“All things being equal, the simplest solution tends to be the best one."</i>
<br><br>
William of Ockham
</html>
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Updates

The original version of this is on [github](https://github.com/matteobrusa/Password-protection-for-static-pages)

I cleaned up the code removing jQuery and updating the crypto lib to use SHA256.
I also added a robots.txt file.

# Password protection for static pages

This simple HTML document helps you protecting static pages or whole websites with no server configuration required: you can now use Dropbox, Amazon S3 or any generic hosting service to host a private, password protected site.
Expand All @@ -17,7 +24,7 @@ The final structure will be:
```
- index.html
- background.jpg
- this-is-a-hash <-- the SHA1 hash of your password
- this-is-a-hash <-- the SHA256 hash of your password
\ - index.html <-- your original index document
```

Expand Down
5 changes: 0 additions & 5 deletions e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4/index.html

This file was deleted.

Binary file removed grunge_patterns.jpg
Binary file not shown.
171 changes: 44 additions & 127 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,134 +1,51 @@

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<style>

body {

background-image: url('grunge_patterns.jpg');
background-attachment: fixed;
color: #333;
}

.box {
border-radius: 3px;
background: rgba(101, 101, 101, 0.7); margin: auto; padding: 12px;
}

.lightbox {
zoom: 1.5;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(10, 10, 10, 0.8);
text-align: center;
margin: auto;

}

div.horizontal {
display: flex;
justify-content: center;
height: 100%;
}

div.vertical {
display: flex;
flex-direction: column;
justify-content: center;
width: 100%;
}

::-webkit-input-placeholder {
color: #955;
text-align: center;
}

::-moz-placeholder {
color: #955;
text-align: center;
}

:-ms-input-placeholder {
color: #955;
text-align: center;
}

</style>

<body>

<div id="loginbox" class="lightbox" >
<div class="horizontal">
<div class="vertical">
<div class="box">
<input style="margin: 16px; text-align: center;" id="password" type="password" placeholder="password" /> <br />
<button id="loginbutton" type="button">Enter</button>
<p id="wrongPassword" style="display: none">wrong password</p>
</div>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body style="margin:0">

<div style="display:flex;justify-content: center;align-items: center;height: 100vh;">
<div>
<form id="form">
<input style="padding: 0.3rem;border: solid;" id="password" type="password" placeholder="password"/>
<input style="padding: 0.3rem;border: solid;background: white;" type="submit" value="Submit">
</form>
</div>
</div>
</div>



<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.0.min.js"></script>


<script type="text/javascript" src="https://rawcdn.githack.com/chrisveness/crypto/7067ee62f18c76dd4a9d372a00e647205460b62b/sha1.js"></script>

<script type="text/javascript">
"use strict";


function loadPage(pwd) {

var hash= pwd;
hash= Sha1.hash(pwd);
var url= hash + "/index.html";

$.ajax({
url : url,
dataType : "html",
success : function(data) {

window.location= url;

},
error : function(xhr, ajaxOptions, thrownError) {


parent.location.hash= hash;

//$("#wrongPassword").show();
$("#password").attr("placeholder","wrong password");
$("#password").val("");
}
});
}


$("#loginbutton").on("click", function() {
loadPage($("#password").val());
});
$("#password").keypress(function(e) {
if (e.which == 13) {

loadPage($("#password").val());

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js" integrity="sha512-nOQuvD9nKirvxDdvQ9OMqe2dgapbPB7vYAMrzJihw5m+aNcf0dX53m6YxM4LgA9u8e9eg9QX+/+mPu8kCNpV2A==" crossorigin="anonymous"></script>

<script type="text/javascript">
function loadPage() {
var pwd = document.getElementById('password').value;
var hash = CryptoJS.SHA256(pwd);
var url = hash + "/index.html";

var request = new XMLHttpRequest();
request.open('GET', url, true);

request.onload = function() {
if (this.status >= 200 && this.status < 400) {
window.location = url;
} else {
alert("Wrong Password");
}
};

request.onerror = function() {
alert("Wrong Password");
};

request.send();
}
});
$("#password").focus();

</script>
document.getElementById("form").addEventListener("submit", function(event){
event.preventDefault()
loadPage();
});
</script>

</body>
</body>
</html>
2 changes: 2 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /