Password Overlay
Di sini, JavaScript btoa
digunakan untuk menyembunyikan teks, sedangkan atob
digunakan untuk mengembalikan teks yang tersembunyi tersebut:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Password Overlay Test</title>
<style>
.body {
padding:10% 0;
text-align:center;
}
.overlay {
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
z-index:9999;
background-color:black;
color:white;
padding:10% 0;
text-align:center;
}
</style>
</head>
<body>
<div id="protect-body" class="body">Content goes here…</div>
<div id="protect-overlay" class="overlay">
<form action="#">
<input name="answer" type="password" placeholder="Password?"/> <button type="submit">Open</button>
</form>
</div>
<script>
// https://developer.mozilla.org/En/DOM/Window.btoa
// https://developer.mozilla.org/en/DOM/window.atob
// to get the obfuscated text, use `console.log(btoa('your text goes here'))`
// `aSBsb3ZlIHlvdQ==` => `i love you`
(function() {
var o = document.getElementById('protect-overlay');
o.getElementsByTagName('form')[0].onsubmit = function() {
if (this.answer.value === atob('aSBsb3ZlIHlvdQ==')) {
o.style.display = "none"; // passed!
} else {
alert('Wrong password!');
}
return false;
};
})();
</script>
</body>
</html>
Demo
Kata kunci: i love you
Referensi
Labels: Eksperimen, JavaScript, Potongan
14 Comments:
apabila ingin mengganti kata kunci nya apakah harus merubah bagian ini mas ?
aSBsb3ZlIHlvdQ==
By Rifan hidayat, at Monday, April 27, 2015 at 10:01:00 AM GMT+7
→ http://jsfiddle.net/tovic/4djLpdby/1
By Taufik Nurrohman, at Monday, April 27, 2015 at 4:47:00 PM GMT+7
diterapin di halaman posting masih ada erornya mas. Waktu enter habis ngisi passwordnya, gak ngilang2 overlaynya..
By Putra, at Monday, April 27, 2015 at 7:14:00 PM GMT+7
\o/
itu namanya kode apa ?
By Rifan hidayat, at Tuesday, April 28, 2015 at 4:33:00 PM GMT+7
mantap mas,, :-bd
By Unknown, at Wednesday, April 29, 2015 at 11:37:00 AM GMT+7
mantab + keren.
By Anonymous, at Tuesday, May 5, 2015 at 12:42:00 AM GMT+7
→ /2013/08/memahami-domcontentloaded.html
By Taufik Nurrohman, at Wednesday, May 13, 2015 at 11:08:00 AM GMT+7
mau tanya dong mas
kalo password overlay nya di pasang ke blogspot bisa ga?
By Niichan, at Monday, June 8, 2015 at 2:54:00 PM GMT+7
Kalau sudah paham cara kerjanya, bisa.
By Taufik Nurrohman, at Wednesday, June 10, 2015 at 12:29:00 PM GMT+7
pasword diganti selain ' i love you ' kok tidak bisa mas taufik.
mohon pencerahannya. terima kasih
By Joko Raharjo, at Thursday, January 21, 2016 at 3:46:00 PM GMT+7
sudah bisa diganti mas. terima kasih
By Joko Raharjo, at Thursday, January 21, 2016 at 4:21:00 PM GMT+7
mau tanya mas. Apa ada cara lain untuk protect-body selain di display:none? soalnya kalo di inspect masih bisa muncul mas :\
By Putra, at Tuesday, July 5, 2016 at 11:23:00 PM GMT+7
Pindah ke CMS Mecha terus pasang plugin private post. Beres!
By Taufik Nurrohman, at Wednesday, July 6, 2016 at 2:29:00 PM GMT+7
Nyari tutorial mbikin cms, udah dibaca tp blm jg paham2. Mungkin bisa dipost mas taufik hehe :)
By Putra, at Wednesday, July 6, 2016 at 7:20:00 PM GMT+7
Post a Comment
<< Home