×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
0
Language: ActionScript
Posted by: Dorian Cuentas
Added: Jul 13, 2015 9:14 PM
Views: 1869
Tags: no tags
  1. package senhafortev2;
  2.  
  3. import com.senhaforte.classes.ChallengeRetorno;
  4. import com.senhaforte.classes.DBc;
  5. import com.senhaforte.classes.Grupo;
  6. import com.senhaforte.classes.Usuario;
  7. import com.senhaforte.security.Challenge;
  8. import javax.persistence.EntityManager;
  9. import org.apache.commons.lang3.RandomStringUtils;
  10.  
  11. /*
  12.  * To change this license header, choose License Headers in Project Properties.
  13.  * To change this template file, choose Tools | Templates
  14.  * and open the template in the editor.
  15.  */
  16. /**
  17.  *
  18.  * @author BrunoRicardox
  19.  */
  20. public class AuthenticationStressUnit {
  21.  
  22.     public static int UPPER_A_INT_VALUE = 65;
  23.  
  24.     /**
  25.      * @param args the command line arguments
  26.      */
  27.     public static void main(String[] args) {
  28.         for (int i = 0; i < 2; i++) {
  29.             AuthenticationStressUnit authenticationStressUnit = new AuthenticationStressUnit();
  30.             authenticationStressUnit.test();
  31.         }
  32.     }
  33.  
  34.     public void test() {
  35.        
  36.         //Cria novo desafio ou busca já criado
  37.         Grupo g = Grupo.BuscaGrupo("NotSelADM", "VdJRYHFK");
  38.  
  39.         Usuario usuario = Usuario.buscaUsuario(g, "dcuentas");
  40.         Usuario.DesbloquearUsuario(g, usuario, 11);
  41.  
  42.         usuario = Usuario.buscaUsuario(g, "dcuentas");
  43.         ChallengeRetorno ret = Challenge.GeraChallenge(g, "dcuentas");
  44.         System.out.println("Desafio a partir de cartão Nº " + ret.getSerial_grid());
  45.         for (String des : ret.getDesafio()) {
  46.             System.out.println(des);
  47.         }
  48.  
  49.         exemplo_usuario.printCartao(usuario.getCartaoGrid());
  50.  
  51.         for (int i = 0; i < 10; i++) {
  52.             char resposta1 = RandomStringUtils.random(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890").charAt(0);
  53.             char resposta2 = RandomStringUtils.random(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890").charAt(0);
  54.             char resposta3 = RandomStringUtils.random(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890").charAt(0);
  55.             System.out.print("probando : " + resposta1 + resposta2 + resposta3);
  56.             String resposta = Challenge.RespostaChallenge(resposta1, resposta2, resposta3, usuario);
  57.             System.out.println(" - " + resposta);
  58.         }
  59.         usuario = Usuario.buscaUsuario(g, "dcuentas");
  60.         char[] validCoords = getValidCoords(Usuario.RetornaGrid(usuario.getCartaoGrid()), ret.getDesafio());
  61.         System.out.print("probando : " + validCoords[0] + validCoords[1] + validCoords[2]);
  62.         String resposta = Challenge.RespostaChallenge(validCoords[0], validCoords[1], validCoords[2], usuario);
  63.         System.out.println(" - " + resposta);
  64.     }
  65.  
  66.     public char[] getValidCoords(char[][] grid, String[] challengeArray) {
  67.         char[] validCoords = new char[3];
  68.         int validCoordsArrayIndex = 0;
  69.         for (String challenge : challengeArray) {
  70.             char coord1 = challenge.charAt(0);
  71.             char coord2 = challenge.charAt(2);
  72.             int numericXCoord = (int) coord2 - UPPER_A_INT_VALUE;
  73.             int numericYCoord = Character.getNumericValue(coord1) - 1;
  74.             validCoords[validCoordsArrayIndex] = grid[numericYCoord][numericXCoord];
  75.             validCoordsArrayIndex++;
  76.         }
  77.         return validCoords;
  78.     }
  79. }
  80.