Sunday, April 26, 2015

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

Lihat Demo


Referensi

Labels: , ,

14 Comments:

At Monday, April 27, 2015 at 10:01:00 AM GMT+7, Blogger Rifan hidayat said...

apabila ingin mengganti kata kunci nya apakah harus merubah bagian ini mas ?

aSBsb3ZlIHlvdQ==

 
At Monday, April 27, 2015 at 4:47:00 PM GMT+7, Blogger Taufik Nurrohman said...

http://jsfiddle.net/tovic/4djLpdby/1

 
At Monday, April 27, 2015 at 7:14:00 PM GMT+7, Blogger Putra said...

diterapin di halaman posting masih ada erornya mas. Waktu enter habis ngisi passwordnya, gak ngilang2 overlaynya..

 
At Tuesday, April 28, 2015 at 4:33:00 PM GMT+7, Blogger Rifan hidayat said...

\o/

itu namanya kode apa ?

 
At Wednesday, April 29, 2015 at 11:37:00 AM GMT+7, Blogger Unknown said...

mantap mas,, :-bd

 
At Tuesday, May 5, 2015 at 12:42:00 AM GMT+7, Anonymous Anonymous said...

mantab + keren.

 
At Wednesday, May 13, 2015 at 11:08:00 AM GMT+7, Blogger Taufik Nurrohman said...

/2013/08/memahami-domcontentloaded.html

 
At Monday, June 8, 2015 at 2:54:00 PM GMT+7, Blogger Niichan said...

mau tanya dong mas
kalo password overlay nya di pasang ke blogspot bisa ga?

 
At Wednesday, June 10, 2015 at 12:29:00 PM GMT+7, Blogger Taufik Nurrohman said...

Kalau sudah paham cara kerjanya, bisa.

 
At Thursday, January 21, 2016 at 3:46:00 PM GMT+7, Blogger Joko Raharjo said...

pasword diganti selain ' i love you ' kok tidak bisa mas taufik.

mohon pencerahannya. terima kasih

 
At Thursday, January 21, 2016 at 4:21:00 PM GMT+7, Blogger Joko Raharjo said...

sudah bisa diganti mas. terima kasih

 
At Tuesday, July 5, 2016 at 11:23:00 PM GMT+7, Blogger Putra said...

mau tanya mas. Apa ada cara lain untuk protect-body selain di display:none? soalnya kalo di inspect masih bisa muncul mas :\

 
At Wednesday, July 6, 2016 at 2:29:00 PM GMT+7, Blogger Taufik Nurrohman said...

Pindah ke CMS Mecha terus pasang plugin private post. Beres!

 
At Wednesday, July 6, 2016 at 7:20:00 PM GMT+7, Blogger Putra said...

Nyari tutorial mbikin cms, udah dibaca tp blm jg paham2. Mungkin bisa dipost mas taufik hehe :)

 

Post a Comment

<< Home