daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.arrow.utils.mysql.accounts;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import com.arrow.server.game.world.entity.player.PlayerInformation;
  7. import com.arrow.utils.Utils;
  8. import com.arrow.utils.mysql.ReadDatabaseQuery;
  9.  
  10. public class CredentialValidation extends ReadDatabaseQuery {
  11.  
  12.     /* Represents the Requested Player Information to validate */
  13.     private PlayerInformation playerInformation;
  14.    
  15.     /* Represents Account Current State */
  16.     private AccountStatus status;
  17.    
  18.     /* Represents Possibly Account States */
  19.     public enum AccountStatus {
  20.         SUCCESSFUL, INVALID_CREDENTIALS, BANNED
  21.     }
  22.    
  23.     /**
  24.      *
  25.      * @param playerInformation
  26.      */
  27.     public CredentialValidation(PlayerInformation playerInformation) {
  28.         setPlayerInformation(playerInformation);
  29.         super.inquiryDatabase();
  30.     }
  31.    
  32.     /*
  33.      * (non-Javadoc)
  34.      * @see com.arrow.utils.mysql.ReadDatabaseQuery#createStatement()
  35.      */
  36.     @Override
  37.     public String createStatement() {
  38.         builder.append("SELECT * FROM characters WHERE username='" + getPlayerInformation().getUsername()+"' LIMIT 1");
  39.         return builder.toString();
  40.     }
  41.  
  42.     /*
  43.      * (non-Javadoc)
  44.      * @see com.arrow.utils.mysql.ReadDatabaseQuery#fetchResult(java.sql.ResultSet)
  45.      */
  46.     @Override
  47.     public void fetchResult(ResultSet result) {
  48.         try {
  49.             while (result.next()) {
  50.                 String password = result.getString("password");
  51.                 String banned = result.getString("bannedTill");
  52.                 if (!getPlayerInformation().getPassword().equals(password)) {
  53.                     setStatus(AccountStatus.INVALID_CREDENTIALS);
  54.                     return;
  55.                 }
  56.                 if (Long.parseLong(banned) > Utils.currentTimeMillis()) {
  57.                     setStatus(AccountStatus.BANNED);
  58.                     return;
  59.                 }
  60.                 setStatus(AccountStatus.SUCCESSFUL);
  61.             }
  62.         } catch (SQLException e) {
  63.             e.printStackTrace();
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * @return the playerInformation
  69.      */
  70.     public PlayerInformation getPlayerInformation() {
  71.         return playerInformation;
  72.     }
  73.  
  74.     /**
  75.      * @param playerInformation the playerInformation to set
  76.      */
  77.     public void setPlayerInformation(PlayerInformation playerInformation) {
  78.         this.playerInformation = playerInformation;
  79.     }
  80.  
  81.     /**
  82.      * @return the status
  83.      */
  84.     public AccountStatus getStatus() {
  85.         return status;
  86.     }
  87.  
  88.     /**
  89.      * @param status the status to set
  90.      */
  91.     public void setStatus(AccountStatus status) {
  92.         this.status = status;
  93.     }
  94.  
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top