/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package integracion.tarjeta.de.coordenadas; import com.senhaforte.action.Utils; import com.senhaforte.classes.ChallengeRetorno; import com.senhaforte.classes.DBc; import com.senhaforte.classes.Grupo; import com.senhaforte.classes.Retorno; import com.senhaforte.classes.Ticket; import com.senhaforte.classes.Usuario; import com.senhaforte.security.Challenge; import com.sun.media.sound.ReferenceCountingDevice; import java.awt.Color; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.Arrays; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.imageio.stream.FileImageOutputStream; import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.MemoryCacheImageOutputStream; import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.SwingUtilities; /** * * @author user */ public class Autenticación { /** * * @param gridArray * @return styles from http://www.tablesgenerator.com/html_tables */ public static StringBuffer createHtmlGrid(String[] gridCharArray) { final StringBuffer htmlStringBuffer = new StringBuffer(); htmlStringBuffer.append(""); htmlStringBuffer.append( "" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "); for (int i = 0; i < gridCharArray.length; i++) { if (((i) % 10 == 0)) { if (i > 9) { htmlStringBuffer.append(" "); } htmlStringBuffer.append( " " + " "); } htmlStringBuffer.append(" "); } htmlStringBuffer.append("
A
BCDEFGHIJ
" + String.valueOf((i / 10) + 1) + "" + gridCharArray[i] + "
"); htmlStringBuffer.append(""); return htmlStringBuffer; } /** * * @param imageOutputStream * @param htmlGrid */ public static void createImageGrid(ImageOutputStream imageOutputStream, String htmlGrid, final int with, final int height) { final JPanel containerComponent = new JPanel(); containerComponent.setBackground(Color.WHITE); JLabel htmlTextComponent = new JLabel(); htmlTextComponent.setBackground(Color.WHITE); htmlTextComponent.setText(htmlGrid); htmlTextComponent.repaint(); containerComponent.setLayout(new GridBagLayout()); containerComponent.add(htmlTextComponent); containerComponent.setSize(with, height); containerComponent.validate(); //create a new image final BufferedImage image = new BufferedImage(containerComponent.getWidth(), containerComponent.getHeight(), BufferedImage.TYPE_INT_ARGB); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { // SwingUtilities.paintComponent(image.createGraphics(), jPanel, new JPanel(), new Rectangle(0, 0, jPanel.getWidth(), jPanel.getHeight())); containerComponent.setSize(with, height); containerComponent.validate(); containerComponent.doLayout(); Graphics2D g = image.createGraphics(); containerComponent.print(g); g.dispose(); ImageIO.write((RenderedImage) image, "png", new File("C:\\Users\\user\\Desktop\\tarjeta.png")); } catch (IOException ex) { Logger.getLogger(Autenticación.class.getName()).log(Level.SEVERE, null, ex); } } }); } public static void main(String[] args) throws IOException { Grupo g = Grupo.BuscaGrupo("NotSel", "NotSelADM", "VdJRYHFK"); //Esta linha adiciona suas credenciais DBc c = new DBc(); //Cria conexao com nosso banco de dados Usuario user = Usuario.buscaUsuario(g, "dcuentas", c); String cartaoGrid = user.getCartaoGrid(); final String[] charArray = cartaoGrid.split(","); final StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("\tA\tB\tC\tD\tE\tF\tG\tH\tI\tJ"); // System.out.print("1\t"); for (int i = 0; i < charArray.length; i++) { if (((i) % 10 == 0)) { stringBuffer.append(""); stringBuffer.append(String.valueOf((i / 10) + 1) + "\t"); } stringBuffer.append(charArray[i] + "\t"); } System.out.println(stringBuffer.toString()); StringBuffer htmlGrid = createHtmlGrid(charArray); createImageGrid(new FileImageOutputStream(new File("C:\\Users\\user\\Desktop\\tarjeta.png")), htmlGrid.toString(), 500, 500); // jPanel.paintComponents(image.createGraphics()); ChallengeRetorno cr = Challenge.GeraChallenge(g, "dcuentas", c); String[] desafio = cr.getDesafio(); System.out.println(""); System.out.println("Desafio criado a partir de Grid - " + cr.getSerial_grid()); System.out.println("Responda ao desafio:"); System.out.println(""); System.out.println("ingrese las coordenadas : " + desafio[0] + " - " + desafio[1] + " - " + desafio[2]); // String geraDesafio = Challenge.geraDesafio(); // System.out.println("desafio : " + geraDesafio); // System.out.println(""); // final int[][] coords = new int[][]{{1, 2}, {1, 2}, {1, 3}}; // char[] BuscaValorGrid = Challenge.BuscaValorGrid(coords, user); // System.out.println(Arrays.toString(BuscaValorGrid)); System.out.println(""); Scanner in = new Scanner(System.in); char[] segredos = new char[3]; segredos[0] = in.nextLine().charAt(0); segredos[1] = in.nextLine().charAt(0); segredos[2] = in.nextLine().charAt(0); System.out.println("enviando coordenadas : " + segredos[0] + " - " + segredos[1] + " - " + segredos[2]); boolean ret = Challenge.RespostaChallenge(c.CriaConn(), segredos[0], segredos[1], segredos[2], user); System.out.println("autenticación : " + ret); } }