Created
May 20, 2020 12:45
-
-
Save janwillemtulp/8968bb6cc207b329913eee893a35bc66 to your computer and use it in GitHub Desktop.
Svelte simple static page password protection
This file contains hidden or 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
<script> | |
let password = '' | |
const hash = s => | |
s.split('').reduce((a, b) => { | |
a = (a << 5) - a + b.charCodeAt(0) | |
return a & a | |
}, 0) | |
$: console.log(password, hash(password)) | |
</script> | |
<style> | |
div { | |
font-family: sans-serif; | |
font-size: 12px; | |
margin-left: 50%; | |
width: 400px; | |
margin-top: 100px; | |
} | |
label { | |
font-weight: bold; | |
} | |
input[type='password'] { | |
width: 200px; | |
} | |
</style> | |
{#if hash(password) === -791498901} | |
<slot /> | |
{:else} | |
<div> | |
<label for="password">Password:</label> | |
<input id="password" bind:value={password} type="password" /> | |
</div> | |
{/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is genius thank you. Chrome now displays warnings in the console for accessibility issues so have had to update the html to silence these: