Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1.                 final String encryptedToken = req.getParameter("token");
  2.  
  3.                 if (encryptedToken == null || encryptedToken.length() == 0 || encryptedToken.length() > 2048) {
  4.                     throw new Exception("Invalid Token");
  5.                 }
  6.  
  7.                 final String encryption_phrase = Settings.instance().getString("email_validation_token_password");
  8.  
  9.                 final String token;
  10.                 try {
  11.                     token = MyWallet.decrypt(encryptedToken, encryption_phrase, MyWallet.DefaultPBKDF2Iterations);
  12.                 } catch (Exception e) {
  13.                     throw new Exception("Error de-serializing token");
  14.                 }
  15.  
  16.                 final JSONParser parser = new JSONParser();
  17.  
  18.                 final JSONObject tokenObj;
  19.                 try {
  20.                     tokenObj = (JSONObject) parser.parse(token);
  21.                 } catch (Exception e) {
  22.                     throw new Exception("Token invalid JSON");
  23.                 }
  24.  
  25.                 final String email_code = tokenObj.get("email_code").toString();
  26.                 final String rguid = tokenObj.get("guid").toString();
  27.                 final long time = Long.valueOf(tokenObj.get("time").toString());
  28.  
  29.                 validateGUIDorThrow(rguid);
  30.  
  31.                 if (System.currentTimeMillis() - time > 3600000) {
  32.                     throw new Exception("Verification Link Expired");
  33.                 }
  34.  
  35.                 //Limit retries
  36.                 Integer retries = (Integer)Cache.get(rguid + VERIFICATION_RETRIES_KEY);
  37.  
  38.                 if (retries == null)
  39.                     retries = 0;
  40.  
  41.                 if (retries >= 10) {
  42.                     throw new ExceptionLowSeverity(strings.getWallet_app().getErrors().getVerification_retry_limit_reached());
  43.                 }
  44.  
  45.                 {
  46.                     if (verifyEmailCode(rguid, email_code)) {
  47.                         logAction(rguid, "verify email", getRealIP(req), req.getHeader("User-Agent"));
  48.  
  49.                         req.setAttribute("initial_success", strings.getWallet_app().getSuccess().getEmail_verified());
  50.                     } else {
  51.                         Connection conn = DatabaseManager.userConn();
  52.                         try {
  53.                             generateAndUpdateEmailCode(conn, rguid);
  54.                         } finally {
  55.                             DatabaseManager.close(conn);
  56.                         }
  57.  
  58.                         Cache.put(rguid + VERIFICATION_RETRIES_KEY, retries+1, 86400);
  59.  
  60.                         logAction(rguid, "error verifying email", getRealIP(req), req.getHeader("User-Agent"));
  61.  
  62.                         req.setAttribute("initial_error", strings.getWallet_app().getErrors().getEmail_code_incorrect());
  63.                     }
  64.                 }
  65.  
  66.                 forwardToIndexPage(req, res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement