X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FCookieUtils.java;h=8d307a22eb4357d7137dc934886303533ad31359;hb=712ddafb749aada41daab85c36ac12f657b2307e;hp=f0820260ffd7365facd6ebedf61d7069efd46bae;hpb=04ae006fdc06b9cbad52f9851ffcb5ad58068318;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/CookieUtils.java b/src/be/nikiroo/utils/CookieUtils.java deleted file mode 100644 index f082026..0000000 --- a/src/be/nikiroo/utils/CookieUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -package be.nikiroo.utils; - -import java.util.Date; - -public class CookieUtils { - /** - * The number of seconds for the period (we accept the current or the - * previous period as valid for a cookie, via "offset"). - */ - static public int GRACE_PERIOD = 3600 * 1000; // between 1 and 2h - - /** - * Generate a new cookie value from the user (email) and an offset. - *

- * You should use an offset of "0" when creating the cookie, and an offset - * of "0" or "-1" if required when checking for the value (the idea is to - * allow a cookie to persist across two timespans; if not, the cookie will - * be expired the very second we switch to a new timespan). - * - * @param value - * the value to generate a cookie for -- you must be able to - * regenerate it in order to check it later - * @param offset - * the offset (should be 0 for creating, 0 then -1 if needed for - * checking) - * - * @return the new cookie - */ - static public String generateCookie(String value, int offset) { - long unixTime = (long) Math.floor(new Date().getTime() / GRACE_PERIOD) - + offset; - return HashUtils.sha512(value + Long.toString(unixTime)); - } - - /** - * Check the given cookie. - * - * @param value - * the value to generate a cookie for -- you must be able to - * regenerate it in order to check it later - * @param cookie - * the cookie to validate - * - * @return TRUE if it is correct - */ - static public boolean validateCookie(String value, String cookie) { - if (cookie != null) - cookie = cookie.trim(); - - String newCookie = generateCookie(value, 0); - if (!newCookie.equals(cookie)) { - newCookie = generateCookie(value, -1); - } - - return newCookie.equals(cookie); - } -}