javascript - Password protect html page -


i need tack simple password protection onto arbitrary html files. need need secure, keep out random roff-raff. tried using below js:

var password;      var thepassword="secretpassword";      password=prompt('enter password',' ');      if (password==thepassword) { alert('correct password! click ok enter!'); }     else { window.location="http://www.google.com/"; }  

this works fine in firefox, seems prompt function fails in ie , redirect google...

any suggestions on how simple password protection using straight html pages?

edit: clear, works fine in firefox, , in ie not prompt popup asking "enter password"

works fine me in ie. demo: http://jsfiddle.net/u2n3p/

one possible reason may not working you're populating prompt empty space, using ' ', when start typing there may space @ end. change prompt to:

password=prompt('enter password', '');  

fyi, know said didn't need super secure, might add some security. md5 library , do, instead:

var thepassword = "md5encodedpassword"; password=prompt('enter password',' '); if(md5(password) != thepassword){ 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -