public boolean validateToken()

in src/main/java/com/amazon/photosharing/utils/TokenGenerator.java [81:112]


    public boolean validateToken(String token, Integer loginTime, TimeUnit timeUnit) {
        try {
            String key = jasypt.decrypt(token);

            String [] keyParts = key.split("\\|");
            String strDate = keyParts[keyParts.length - 1];
            Date date = format.parse(strDate);

            Date currentTime = new Date();

            long duration = currentTime.getTime() - date.getTime();
            long diff;

            if (timeUnit.equals(TimeUnit.MINUTES))
                diff = TimeUnit.MILLISECONDS.toMinutes(duration);
            else if (timeUnit.equals(TimeUnit.SECONDS))
                diff = TimeUnit.MILLISECONDS.toSeconds(duration);
            else
                throw new UnsupportedOperationException(timeUnit.toString() + " not supported");

            if (diff > loginTime)
                return false;

            return true;
        }

        catch (Exception exc) {
            exc.printStackTrace();

            return false;
        }
    }