{"id":3213,"date":"2014-01-21T09:00:24","date_gmt":"2014-01-21T08:00:24","guid":{"rendered":"https:\/\/blogs.ua.es\/pi\/?p=3213"},"modified":"2013-12-02T11:29:28","modified_gmt":"2013-12-02T10:29:28","slug":"uso-de-cookies-para-mantener-la-persistencia-de-un-login","status":"publish","type":"post","link":"https:\/\/blogs.ua.es\/pi\/2014\/01\/21\/uso-de-cookies-para-mantener-la-persistencia-de-un-login\/","title":{"rendered":"Uso de cookies para mantener la persistencia de un login"},"content":{"rendered":"<p>A mis alumnos, en la\u00a0<a href=\"http:\/\/hdl.handle.net\/10045\/33835\">Pr\u00e1ctica 9: PHP 2 (cookies y sesiones)<\/a> les pido que implementen la t\u00edpica opci\u00f3n de &#8220;recordarme&#8221; que existe en muchos sitios web. Las cosas que uno ve son muchas veces sorprendentes, pero pocas veces veo algo que realmente sea correcto&#8230; el guardar directamente el nombre de usuario y la contrase\u00f1a en una cookie no es muy seguro \ud83d\ude42<\/p>\n<p>Sobre este tema no hay mucha informaci\u00f3n. He intentado averiguar c\u00f3mo lo hacen sitios web como Google o Facebook, pero no encuentro informaci\u00f3n sobre ello. \u00bfAlguien lo sabe?<\/p>\n<p>Lo mejor que he encontrado es el art\u00edculo\u00a0<a href=\"http:\/\/fishbowl.pastiche.org\/2004\/01\/19\/persistent_login_cookie_best_practice\/\">Persistent Login Cookie Best Practice<\/a>. La soluci\u00f3n que propone es f\u00e1cil de entender e implementar:<\/p>\n<blockquote><p>The cookie should consist of the user&#8217;s username, followed by a separator character, followed by some large random number (128 bits seems mind-bogglingly large enough to be acceptable). The server keeps a table of number-&gt;username associations, which is looked up to verify the validity of the cookie. If the cookie supplies a random number and username that are mapped to each other in the table, the login is accepted.<\/p>\n<p>At any time, a username may be mapped to several such numbers. Also, while incredibly unlikely, it does not matter if two usernames are mapped to the same random number.<\/p>\n<p>A persistent cookie is good for a single login. When authentication is confirmed, the random number used to log in is invalidated and a brand new cookie assigned. Standard session-management handles the credentials for the life of the session, so the newly assigned cookie will not be checked until the <em>next<\/em> session (at which point it, too, will be invalidated after use).<\/p>\n<p>The server need not make the effort of deliberately trying to avoid re-assigning random numbers that have been used before: the chance of it happening is so low that even if it did, nobody would know to make use of it.<\/p>\n<p>When a user logs out through some deliberate logout function, their current cookie number is also invalidated. The user also has an option somewhere to clear <em>all<\/em> persistent logins being remembered by the system, just in case.<\/p>\n<p>Periodically, the database is purged of associations older than a certain time-period (three months, perhaps: the size of the table would be far more an issue than any possibilities of collision in a 128 bit random space).<\/p>\n<p>The following user functions must <em>not<\/em> be reachable through a cookie-based login, but only through the typing of a valid password:<\/p>\n<ul>\n<li>Changing the user&#8217;s password<\/li>\n<li>Changing the user&#8217;s email address (especially if email-based password recovery is used)<\/li>\n<li>Any access to the user&#8217;s address, payment details or financial information<\/li>\n<li>Any ability to make a purchase<\/li>\n<\/ul>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>A mis alumnos, en la\u00a0Pr\u00e1ctica 9: PHP 2 (cookies y sesiones) les pido que implementen la t\u00edpica opci\u00f3n de &#8220;recordarme&#8221; que existe en muchos sitios web. Las cosas que uno ve son muchas veces sorprendentes, pero pocas veces veo algo &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/blogs.ua.es\/pi\/2014\/01\/21\/uso-de-cookies-para-mantener-la-persistencia-de-un-login\/\"> <span class=\"screen-reader-text\">Uso de cookies para mantener la persistencia de un login<\/span> Leer M\u00e1s  &raquo;<\/a><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[159999,488],"class_list":["post-3213","post","type-post","status-publish","format-standard","hentry","category-general","tag-cookies","tag-seguridad"],"_links":{"self":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/comments?post=3213"}],"version-history":[{"count":1,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3213\/revisions"}],"predecessor-version":[{"id":3214,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3213\/revisions\/3214"}],"wp:attachment":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/media?parent=3213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/categories?post=3213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/tags?post=3213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}