Note that there are some explanatory texts on larger screens.

plurals
  1. POCookie not being read
    text
    copied!<p>I implemented "Remember me" functionality in my web app. I did this using a cookie that contains username/password encrypted using RSA.</p> <p>I add the cookie when I login; if then I logout (without closing browser) the cookie is read ok and in the login page I see username/pass already typed. But if I close the browser; or close tab and run the application again, when the cookies are read, the only cookie that is read is the JSESSIONID. the cookie with the credentials is not in the array returned by <code>((HttpServletRequest)facesContext.getExternalContext().getRequest()).getCookies(­);</code> even though I can see it in the browser. why is that?</p> <p>This is the code that creates the cookie:</p> <pre><code>String credentials = username + "?" + password; Cookie c = CookieHandler.getInstance().createCookie("vtcred", credentials, rememberMe); FacesContext facesContext = FacesContext.getCurrentInstance(); ((HttpServletResponse) facesContext.getExternalContext().getResponse()).addCookie(c); </code></pre> <p>and method createCookie:</p> <pre><code>public Cookie createCookie(String name, String value, boolean rememberMe) { value = encript(value); Cookie credCookie = new Cookie(name, value); credCookie.setHttpOnly(true); if(rememberMe) { credCookie.setMaxAge(86400); } else { credCookie.setMaxAge(0); } return credCookie; } </code></pre> <p>Edit: I am setting the cookie's max age to one day; and in the browser I can see that the cookie expires tomorrow, so that's not the problem</p> <p>Thanks in advance, Damian</p> <p>edit2: this is very odd, but it seems to be working now. I'll keep testing it and notify. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload