/*
* 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
*/
htmlStringBuffer.append("<html>");
htmlStringBuffer.append(
"<style type=\"text/css\">"
+ ".table width:700px;height:350px"
+ ".th height:10px"
+ ".tg {border-collapse:collapse;border-spacing:0;border-color:#aabcfe;}"
+ ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aabcfe;color:#669;background-color:#e8edff;}"
+ ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#aabcfe;color:#039;background-color:#b9c9fe;}"
+ ".tg .tg-s6z2{text-align:center}"
+ ".tg .tg-igvl{background-color:#b9c9fe;color:#003399;text-align:center}"
+ "</style>"
+ "<table class=\"tg\">"
+ " <tr>"
+ " <th class=\"tg-s6z2\"></th>"
+ " <th class=\"tg-s6z2\">A<br></th>"
+ " <th class=\"tg-s6z2\">B</th>"
+ " <th class=\"tg-s6z2\">C</th>"
+ " <th class=\"tg-s6z2\">D</th>"
+ " <th class=\"tg-s6z2\">E</th>"
+ " <th class=\"tg-s6z2\">F</th>"
+ " <th class=\"tg-s6z2\">G</th>"
+ " <th class=\"tg-s6z2\">H</th>"
+ " <th class=\"tg-s6z2\">I</th>"
+ " <th class=\"tg-s6z2\">J</th>"
+ " </tr>"
+ "");
for (int i = 0; i < gridCharArray.length; i++) {
if (((i) % 10 == 0)) {
if (i > 9) {
htmlStringBuffer.append(" </tr>");
}
htmlStringBuffer.append(
" <tr>" + " <td class=\"tg-igvl\">" + String.
valueOf((i
/ 10) + 1) + "</td>");
}
htmlStringBuffer.append(" <td class=\"tg-s6z2\">" + gridCharArray[i] + "</td>");
}
htmlStringBuffer.append("</table>");
htmlStringBuffer.append("</html>");
return htmlStringBuffer;
}
/**
*
* @param imageOutputStream
* @param htmlGrid
*/
public static void createImageGrid
(ImageOutputStream imageOutputStream,
String htmlGrid,
final int with,
final int height
) {
containerComponent.
setBackground(Color.
WHITE);
htmlTextComponent.
setBackground(Color.
WHITE);
htmlTextComponent.setText(htmlGrid);
htmlTextComponent.repaint();
containerComponent.add(htmlTextComponent);
containerComponent.setSize(with, height);
containerComponent.validate();
//create a new image
@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();
containerComponent.print(g);
g.dispose();
ImageIO.
write((RenderedImage) image,
"png",
new File("C:\\Users\\user\\Desktop\\tarjeta.png"));
Logger.getLogger(Autenticación.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
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(",");
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());
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("Desafio criado a partir de Grid - " + cr.
getSerial_grid());
System.
out.
println("Responda ao desafio:");
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));
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
);
}
}