0

I found on the internet the simpliest way to prompt a page for a Password with some Jquery, But Every time the page refreshed it prompts me again, which I would like to pass on

Could you please advise if this is possible,

I have one Manager page which needs to be password protected. but it will Refresh a few times when doing actions,

var password; var thePassword="Pass!@#$"; password=prompt('Enter Password',' '); if (password==thePassword) {} else { alert('Wrong Password! Click OK to Enter!');

Thanks for advising

Regards JqueryDummy

2 Answers2

0

You might want to look into a server side language such as PHP as jQuery is solely client side and any implementations will be insecure.

DrRoach
  • 1,320
  • 9
  • 16
  • OK, I actually took jQuery as this is a internal server, so for Security I don't really have worry – Richard TI Oct 20 '14 at 11:17
  • But if someone disables their JavaScript on their browser they can easily bypass this. If you still want to stick with JQuery you will need to use cookies. See [How to set, read and delete a cookie](http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery) – ahb Oct 20 '14 at 11:22
  • I will try the cookies out, php will not work for this server solution – Richard TI Oct 20 '14 at 11:39
  • Cookies are a part of PHP – DrRoach Oct 20 '14 at 11:51
  • What could help is a remember me cookie for 1 day, my server app doesn't support PHP unfortunately, Could this work in Java ? – Richard TI Oct 21 '14 at 06:49
  • Your server doesn't support PHP? and no cookies are solely part of PHP sorry – DrRoach Oct 21 '14 at 08:14
0

Solved it to: cookie based, I know it's not the perfect code but it works on the internal Appserver :)

    function checkCookie() {
        var user=getCookie("username");
     var password; 
     var thePassword="Pass!@#$"; 
     if (user != "") {}
     else {
     $("#container").fadeOut();
         password=prompt('Enter Password',' '); 
       if (password==thePassword) {
       user ="ADMIN";
       setCookie("username", user, 1);
       $("#container").fadeIn();
       }
       else { 
        alert('Wrong Password! Click OK to Enter!');
        password=prompt('Enter Password',' '); 
        if (password==thePassword) {
        user ="ADMIN";
        setCookie("username", user, 1);
        $("#container").fadeIn();
        }
        else { window.location="http://www.google.com/"; }  } }
               }
// And offcourse the basic Cookie Create code 
function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*60));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) != -1) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

Thanks for the hints in the comments (AHB) Regards JqueryDummy