Jump to content

Archived

This topic is now archived and is closed to further replies.

Pedroalves

[Resolvido] Incriptação

Recommended Posts

O que exatamente você quer fazer? Dá uma pesquisada em MessageDigest. Tem vários algoritmos para encriptação: MD5, SHA1, etc. Você pode por exemplo criptografar uma senha num formulário de cadastro e salvá-la no banco. É isso?

Exemplo:

try  {  
 String senha = "senha";  
 MessageDigest md = MessageDigest.getInstance("MD5");  

 md.update(senha.getBytes());  
 BigInteger hash = new BigInteger(1, md.digest());  
 String senhaCriptografada = hash.toString(16);  
} catch(NoSuchAlgorithmException ex)  {  
 ex.printStackTrace();  
}

Share this post


Link to post
Share on other sites

Bem! Agora, na hora que o usuário for fazer o login no sistema, basta você recuperar a senha do usuário que está criptografada no banco, pegar a senha preenchida pelo usuário e criptografá-la com o mesmo algoritmo da que está no banco de dados; após, comparar as duas com equals.

Share this post


Link to post
Share on other sites

não estou a conseguir a por a password incriptar podia me dizer a onde estou a fazer mal

/*
* GESTAOSTOCKSView.java
*/

package gestaostocks;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.sql.*;
import java.awt.PrintJob;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.Font;
import java.awt.Frame;
import java.security.*;
import java.security.MessageDigest;
import java.security.Security;
import java.net.*;
import java.io.*;
import java.math.BigInteger;

/**
* The application's main frame.
*/
public class GESTAOSTOCKSView extends FrameView {
Connection conn = null;
   public GESTAOSTOCKSView(SingleFrameApplication app) {
       super(app);

       initComponents();
this.getFrame().setBounds(100, 200, 300, 200);
       // status bar initialization - message timeout, idle icon and busy animation, etc
       ResourceMap resourceMap = getResourceMap();
       int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
       messageTimer = new Timer(messageTimeout, new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               statusMessageLabel.setText("");
           }
       });
       messageTimer.setRepeats(false);
       int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
       for (int i = 0; i < busyIcons.length; i++) {
           busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
       }
       busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
               statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
           }
       });
       idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
       statusAnimationLabel.setIcon(idleIcon);
       progressBar.setVisible(false);

       // connecting action tasks to status bar via TaskMonitor
       TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
       taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
           public void propertyChange(java.beans.PropertyChangeEvent evt) {
               String propertyName = evt.getPropertyName();
               if ("started".equals(propertyName)) {
                   if (!busyIconTimer.isRunning()) {
                       statusAnimationLabel.setIcon(busyIcons[0]);
                       busyIconIndex = 0;
                       busyIconTimer.start();
                   }
                   progressBar.setVisible(true);
                   progressBar.setIndeterminate(true);
               } else if ("done".equals(propertyName)) {
                   busyIconTimer.stop();
                   statusAnimationLabel.setIcon(idleIcon);
                   progressBar.setVisible(false);
                   progressBar.setValue(0);
               } else if ("message".equals(propertyName)) {
                   String text = (String)(evt.getNewValue());
                   statusMessageLabel.setText((text == null) ? "" : text);
                   messageTimer.restart();
               } else if ("progress".equals(propertyName)) {
                   int value = (Integer)(evt.getNewValue());
                   progressBar.setVisible(true);
                   progressBar.setIndeterminate(false);
                   progressBar.setValue(value);
               }
           }
       });
   }

   @Action
   public void showAboutBox() {
       if (aboutBox == null) {
           JFrame mainFrame = GESTAOSTOCKSApp.getApplication().getMainFrame();
           aboutBox = new GESTAOSTOCKSAboutBox(mainFrame);
           aboutBox.setLocationRelativeTo(mainFrame);
       }
       GESTAOSTOCKSApp.getApplication().show(aboutBox);
   }

   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {

       mainPanel = new javax.swing.JPanel();
       jLabel1 = new javax.swing.JLabel();
       jLabel2 = new javax.swing.JLabel();
       USERNAME = new javax.swing.JTextField();
       jLabel3 = new javax.swing.JLabel();
       PASSWORD = new javax.swing.JPasswordField();
       jButton1 = new javax.swing.JButton();
       jButton2 = new javax.swing.JButton();
       jButton5 = new javax.swing.JButton();
       menuBar = new javax.swing.JMenuBar();
       javax.swing.JMenu fileMenu = new javax.swing.JMenu();
       javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
       javax.swing.JMenu helpMenu = new javax.swing.JMenu();
       javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
       statusPanel = new javax.swing.JPanel();
       javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
       statusMessageLabel = new javax.swing.JLabel();
       statusAnimationLabel = new javax.swing.JLabel();
       progressBar = new javax.swing.JProgressBar();
       ERRO = new javax.swing.JFrame();
       jLabel4 = new javax.swing.JLabel();
       jButton3 = new javax.swing.JButton();
       MENUPRINCIPAL = new javax.swing.JFrame();
       ERROConection = new javax.swing.JFrame();
       jButton4 = new javax.swing.JButton();
       jLabel5 = new javax.swing.JLabel();
       REGISTO = new javax.swing.JFrame();
       jButton6 = new javax.swing.JButton();
       jLabel6 = new javax.swing.JLabel();
       jLabel7 = new javax.swing.JLabel();
       novoutilizador = new javax.swing.JTextField();
       jLabel8 = new javax.swing.JLabel();
       jLabel9 = new javax.swing.JLabel();
       jLabel10 = new javax.swing.JLabel();
       jLabel11 = new javax.swing.JLabel();
       jLabel12 = new javax.swing.JLabel();
       novapassword = new javax.swing.JPasswordField();
       novomail = new javax.swing.JTextField();
       novo_nome_utilizador = new javax.swing.JTextField();
       Morada = new javax.swing.JTextField();
       Telefone = new javax.swing.JTextField();
       jLabel13 = new javax.swing.JLabel();
       Nif = new javax.swing.JTextField();
       jLabel14 = new javax.swing.JLabel();
       BI = new javax.swing.JTextField();
       jLabel15 = new javax.swing.JLabel();
       jButton7 = new javax.swing.JButton();
       jButton8 = new javax.swing.JButton();
       jComboBox1 = new javax.swing.JComboBox();

       mainPanel.setName("mainPanel"); // NOI18N

       org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gestaostocks.GESTAOSTOCKSApp.class).getContext().getResourceMap(GESTAOSTOCKSView.class);
       jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
       jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
       jLabel1.setName("jLabel1"); // NOI18N

       jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
       jLabel2.setName("jLabel2"); // NOI18N

       USERNAME.setText(resourceMap.getString("USERNAME.text")); // NOI18N
       USERNAME.setName("USERNAME"); // NOI18N

       jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
       jLabel3.setName("jLabel3"); // NOI18N

       PASSWORD.setText(resourceMap.getString("PASSWORD.text")); // NOI18N
       PASSWORD.setName("PASSWORD"); // NOI18N

       javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gestaostocks.GESTAOSTOCKSApp.class).getContext().getActionMap(GESTAOSTOCKSView.class, this);
       jButton1.setAction(actionMap.get("LOGIN")); // NOI18N
       jButton1.setName("jButton1"); // NOI18N

       jButton2.setAction(actionMap.get("quit")); // NOI18N
       jButton2.setName("jButton2"); // NOI18N

       jButton5.setAction(actionMap.get("REGISTO")); // NOI18N
       jButton5.setName("jButton5"); // NOI18N

       javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
       mainPanel.setLayout(mainPanelLayout);
       mainPanelLayout.setHorizontalGroup(
           mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(mainPanelLayout.createSequentialGroup()
               .addGap(109, 109, 109)
               .addComponent(jLabel1)
               .addContainerGap(60, Short.MAX_VALUE))
           .addGroup(mainPanelLayout.createSequentialGroup()
               .addGap(89, 89, 89)
               .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                   .addGroup(mainPanelLayout.createSequentialGroup()
                       .addComponent(jButton1)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                       .addComponent(jButton5)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                       .addComponent(jButton2))
                   .addGroup(mainPanelLayout.createSequentialGroup()
                       .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                               .addComponent(jLabel2)
                               .addGap(18, 18, 18))
                           .addGroup(mainPanelLayout.createSequentialGroup()
                               .addComponent(jLabel3)
                               .addGap(15, 15, 15)))
                       .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                           .addComponent(PASSWORD, javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(USERNAME, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))))
               .addGap(105, 105, 105))
       );
       mainPanelLayout.setVerticalGroup(
           mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(mainPanelLayout.createSequentialGroup()
               .addGap(27, 27, 27)
               .addComponent(jLabel1)
               .addGap(45, 45, 45)
               .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(USERNAME, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(jLabel2))
               .addGap(18, 18, 18)
               .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                   .addComponent(jLabel3)
                   .addComponent(PASSWORD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(54, 54, 54)
               .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jButton1)
                   .addComponent(jButton2)
                   .addComponent(jButton5))
               .addContainerGap(87, Short.MAX_VALUE))
       );

       menuBar.setName("menuBar"); // NOI18N

       fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
       fileMenu.setName("fileMenu"); // NOI18N

       exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
       exitMenuItem.setName("exitMenuItem"); // NOI18N
       fileMenu.add(exitMenuItem);

       menuBar.add(fileMenu);

       helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
       helpMenu.setName("helpMenu"); // NOI18N

       aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
       aboutMenuItem.setName("aboutMenuItem"); // NOI18N
       helpMenu.add(aboutMenuItem);

       menuBar.add(helpMenu);

       statusPanel.setName("statusPanel"); // NOI18N

       statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

       statusMessageLabel.setName("statusMessageLabel"); // NOI18N

       statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
       statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

       progressBar.setName("progressBar"); // NOI18N

       javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
       statusPanel.setLayout(statusPanelLayout);
       statusPanelLayout.setHorizontalGroup(
           statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
           .addGroup(statusPanelLayout.createSequentialGroup()
               .addContainerGap()
               .addComponent(statusMessageLabel)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 318, Short.MAX_VALUE)
               .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addComponent(statusAnimationLabel)
               .addContainerGap())
       );
       statusPanelLayout.setVerticalGroup(
           statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(statusPanelLayout.createSequentialGroup()
               .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(statusMessageLabel)
                   .addComponent(statusAnimationLabel)
                   .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(3, 3, 3))
       );

       ERRO.setName("ERRO"); // NOI18N

       jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
       jLabel4.setName("jLabel4"); // NOI18N

       jButton3.setAction(actionMap.get("VOLTAR")); // NOI18N
       jButton3.setName("jButton3"); // NOI18N

       javax.swing.GroupLayout ERROLayout = new javax.swing.GroupLayout(ERRO.getContentPane());
       ERRO.getContentPane().setLayout(ERROLayout);
       ERROLayout.setHorizontalGroup(
           ERROLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(ERROLayout.createSequentialGroup()
               .addGroup(ERROLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(ERROLayout.createSequentialGroup()
                       .addGap(136, 136, 136)
                       .addComponent(jLabel4))
                   .addGroup(ERROLayout.createSequentialGroup()
                       .addGap(123, 123, 123)
                       .addComponent(jButton3)))
               .addContainerGap(206, Short.MAX_VALUE))
       );
       ERROLayout.setVerticalGroup(
           ERROLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(ERROLayout.createSequentialGroup()
               .addGap(89, 89, 89)
               .addComponent(jLabel4)
               .addGap(44, 44, 44)
               .addComponent(jButton3)
               .addContainerGap(130, Short.MAX_VALUE))
       );

       MENUPRINCIPAL.setName("MENUPRINCIPAL"); // NOI18N

       javax.swing.GroupLayout MENUPRINCIPALLayout = new javax.swing.GroupLayout(MENUPRINCIPAL.getContentPane());
       MENUPRINCIPAL.getContentPane().setLayout(MENUPRINCIPALLayout);
       MENUPRINCIPALLayout.setHorizontalGroup(
           MENUPRINCIPALLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGap(0, 400, Short.MAX_VALUE)
       );
       MENUPRINCIPALLayout.setVerticalGroup(
           MENUPRINCIPALLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGap(0, 300, Short.MAX_VALUE)
       );

       ERROConection.setName("ERROConection"); // NOI18N

       jButton4.setAction(actionMap.get("OK")); // NOI18N
       jButton4.setName("jButton4"); // NOI18N

       jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
       jLabel5.setName("jLabel5"); // NOI18N

       javax.swing.GroupLayout ERROConectionLayout = new javax.swing.GroupLayout(ERROConection.getContentPane());
       ERROConection.getContentPane().setLayout(ERROConectionLayout);
       ERROConectionLayout.setHorizontalGroup(
           ERROConectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(ERROConectionLayout.createSequentialGroup()
               .addGroup(ERROConectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(ERROConectionLayout.createSequentialGroup()
                       .addGap(142, 142, 142)
                       .addComponent(jLabel5))
                   .addGroup(ERROConectionLayout.createSequentialGroup()
                       .addGap(177, 177, 177)
                       .addComponent(jButton4)))
               .addContainerGap(153, Short.MAX_VALUE))
       );
       ERROConectionLayout.setVerticalGroup(
           ERROConectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ERROConectionLayout.createSequentialGroup()
               .addContainerGap(71, Short.MAX_VALUE)
               .addComponent(jLabel5)
               .addGap(71, 71, 71)
               .addComponent(jButton4)
               .addGap(121, 121, 121))
       );

       REGISTO.setName("REGISTO"); // NOI18N

       jButton6.setAction(actionMap.get("Registarutilizador")); // NOI18N
       jButton6.setName("jButton6"); // NOI18N

       jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
       jLabel6.setName("jLabel6"); // NOI18N

       jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
       jLabel7.setName("jLabel7"); // NOI18N

       novoutilizador.setText(resourceMap.getString("novoutilizador.text")); // NOI18N
       novoutilizador.setName("novoutilizador"); // NOI18N

       jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
       jLabel8.setName("jLabel8"); // NOI18N

       jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
       jLabel9.setName("jLabel9"); // NOI18N

       jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
       jLabel10.setName("jLabel10"); // NOI18N

       jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
       jLabel11.setName("jLabel11"); // NOI18N

       jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
       jLabel12.setName("jLabel12"); // NOI18N

       novapassword.setText(resourceMap.getString("novapassword.text")); // NOI18N
       novapassword.setName("novapassword"); // NOI18N

       novomail.setText(resourceMap.getString("novomail.text")); // NOI18N
       novomail.setName("novomail"); // NOI18N

       novo_nome_utilizador.setText(resourceMap.getString("novo_nome_utilizador.text")); // NOI18N
       novo_nome_utilizador.setName("novo_nome_utilizador"); // NOI18N

       Morada.setText(resourceMap.getString("Morada.text")); // NOI18N
       Morada.setName("Morada"); // NOI18N

       Telefone.setText(resourceMap.getString("Telefone.text")); // NOI18N
       Telefone.setName("Telefone"); // NOI18N

       jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
       jLabel13.setName("jLabel13"); // NOI18N

       Nif.setText(resourceMap.getString("Nif.text")); // NOI18N
       Nif.setName("Nif"); // NOI18N

       jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
       jLabel14.setName("jLabel14"); // NOI18N

       BI.setText(resourceMap.getString("BI.text")); // NOI18N
       BI.setName("BI"); // NOI18N

       jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
       jLabel15.setName("jLabel15"); // NOI18N

       jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
       jButton7.setName("jButton7"); // NOI18N

       jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
       jButton8.setName("jButton8"); // NOI18N

       jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
       jComboBox1.setName("jComboBox1"); // NOI18N

       javax.swing.GroupLayout REGISTOLayout = new javax.swing.GroupLayout(REGISTO.getContentPane());
       REGISTO.getContentPane().setLayout(REGISTOLayout);
       REGISTOLayout.setHorizontalGroup(
           REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(REGISTOLayout.createSequentialGroup()
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                       .addGroup(REGISTOLayout.createSequentialGroup()
                           .addContainerGap()
                           .addComponent(jLabel7)
                           .addGap(18, 18, 18)
                           .addComponent(novoutilizador))
                       .addGroup(REGISTOLayout.createSequentialGroup()
                           .addContainerGap()
                           .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                               .addComponent(jLabel8)
                               .addComponent(jLabel9)
                               .addComponent(jLabel10)
                               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel13)
                                   .addComponent(jLabel11)))
                           .addGap(18, 18, 18)
                           .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                               .addComponent(novo_nome_utilizador, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                               .addComponent(novapassword, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                               .addComponent(novomail, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                               .addComponent(Morada)
                               .addGroup(REGISTOLayout.createSequentialGroup()
                                   .addComponent(jButton6)
                                   .addGap(18, 18, 18)
                                   .addComponent(jButton7)
                                   .addGap(18, 18, 18)
                                   .addComponent(jButton8))
                               .addGroup(REGISTOLayout.createSequentialGroup()
                                   .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                       .addComponent(Telefone, javax.swing.GroupLayout.Alignment.LEADING)
                                       .addComponent(Nif, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
                                   .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                       .addGroup(REGISTOLayout.createSequentialGroup()
                                           .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                           .addComponent(jLabel14)
                                           .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                           .addComponent(BI, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                                       .addGroup(REGISTOLayout.createSequentialGroup()
                                           .addGap(1, 1, 1)
                                           .addComponent(jLabel15)
                                           .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                           .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))))
                   .addGroup(REGISTOLayout.createSequentialGroup()
                       .addContainerGap()
                       .addComponent(jLabel12))
                   .addGroup(REGISTOLayout.createSequentialGroup()
                       .addGap(193, 193, 193)
                       .addComponent(jLabel6)))
               .addContainerGap(103, Short.MAX_VALUE))
       );
       REGISTOLayout.setVerticalGroup(
           REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(REGISTOLayout.createSequentialGroup()
               .addGap(19, 19, 19)
               .addComponent(jLabel6)
               .addGap(33, 33, 33)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel7)
                   .addComponent(novoutilizador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(18, 18, 18)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel8)
                   .addComponent(novapassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(18, 18, 18)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel9)
                   .addComponent(novomail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(18, 18, 18)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel10)
                   .addComponent(novo_nome_utilizador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel11)
                   .addComponent(Morada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel13)
                   .addComponent(Nif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(jLabel14)
                   .addComponent(BI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jLabel12)
                   .addComponent(Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                   .addComponent(jLabel15)
                   .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(18, 18, 18)
               .addGroup(REGISTOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(jButton6)
                   .addComponent(jButton7)
                   .addComponent(jButton8))
               .addGap(23, 23, 23))
       );

       setComponent(mainPanel);
       setMenuBar(menuBar);
       setStatusBar(statusPanel);
   }// </editor-fold>
/******************************************************************************
* Copyright (c) 2000 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/


/**
* implementation of MD5 as outlined in "Handbook of Applied Cryptography", pages 346 - 347.
*/
public class MD5Digest
   extends GeneralDigest
{
   private static final int    DIGEST_LENGTH = 16;

   private int     H1, H2, H3, H4;         // IV's

   private int[]   X = new int[16];
   private int     xOff;

   /**
    * Standard constructor
    */
   public MD5Digest()
   {
       reset();
   }

   /**
    * Copy constructor.  This will copy the state of the provided
    * message digest.
    */
   public MD5Digest(MD5Digest t)
   {
       super(t);

       H1 = t.H1;
       H2 = t.H2;
       H3 = t.H3;
       H4 = t.H4;

       System.arraycopy(t.X, 0, X, 0, t.X.length);
       xOff = t.xOff;
   }

   public String getAlgorithmName()
   {
       return "MD5";
   }

   public int getDigestSize()
   {
       return DIGEST_LENGTH;
   }

   protected void processWord(
       byte[]  in,
       int     inOff)
   {
       X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8)
           | ((in[inOff + 2] & 0xff) << 16) | ((in[inOff + 3] & 0xff) << 24);

       if (xOff == 16)
       {
           processBlock();
       }
   }

   protected void processLength(
       long    bitLength)
   {
       if (xOff > 14)
       {
           processBlock();
       }

       X[14] = (int)(bitLength & 0xffffffff);
       X[15] = (int)(bitLength >>> 32);
   }

   private void unpackWord(
       int     word,
       byte[]  out,
       int     outOff)
   {
       out[outOff]     = (byte)word;
       out[outOff + 1] = (byte)(word >>> 8);
       out[outOff + 2] = (byte)(word >>> 16);
       out[outOff + 3] = (byte)(word >>> 24);
   }

   public int doFinal(
       byte[]  out,
       int     outOff)
   {
       finish();

       unpackWord(H1, out, outOff);
       unpackWord(H2, out, outOff + 4);
       unpackWord(H3, out, outOff + 8);
       unpackWord(H4, out, outOff + 12);

       reset();

       return DIGEST_LENGTH;
   }

   /**
    * reset the chaining variables to the IV values.
    */
   public void reset()
   {
       super.reset();

       H1 = 0x67452301;
       H2 = 0xefcdab89;
       H3 = 0x98badcfe;
       H4 = 0x10325476;

       xOff = 0;

       for (int i = 0; i != X.length; i++)
       {
           X[i] = 0;
       }
   }

   //
   // round 1 left rotates
   //
   private static final int S11 = 7;
   private static final int S12 = 12;
   private static final int S13 = 17;
   private static final int S14 = 22;

   //
   // round 2 left rotates
   //
   private static final int S21 = 5;
   private static final int S22 = 9;
   private static final int S23 = 14;
   private static final int S24 = 20;

   //
   // round 3 left rotates
   //
   private static final int S31 = 4;
   private static final int S32 = 11;
   private static final int S33 = 16;
   private static final int S34 = 23;

   //
   // round 4 left rotates
   //
   private static final int S41 = 6;
   private static final int S42 = 10;
   private static final int S43 = 15;
   private static final int S44 = 21;

   /*
    * rotate int x left n bits.
    */
   private int rotateLeft(
       int x,
       int n)
   {
       return (x << n) | (x >>> (32 - n));
   }

   /*
    * F, G, H and I are the basic MD5 functions.
    */
   private int F(
       int u,
       int v,
       int w)
   {
       return (u & v) | (~u & w);
   }

   private int G(
       int u,
       int v,
       int w)
   {
       return (u & w) | (v & ~w);
   }

   private int H(
       int u,
       int v,
       int w)
   {
       return u ^ v ^ w;
   }

   private int K(
       int u,
       int v,
       int w)
   {
       return v ^ (u | ~w);
   }

   protected void processBlock()
   {
       int a = H1;
       int b = H2;
       int c = H3;
       int d = H4;

       //
       // Round 1 - F cycle, 16 times.
       //
       a = rotateLeft(a + F(b, c, d) + X[ 0] + 0xd76aa478, S11) + b;
       d = rotateLeft(d + F(a, b, c) + X[ 1] + 0xe8c7b756, S12) + a;
       c = rotateLeft(c + F(d, a, B) + X[ 2] + 0x242070db, S13) + d;
       b = rotateLeft(b + F(c, d, a) + X[ 3] + 0xc1bdceee, S14) + c;
       a = rotateLeft(a + F(b, c, d) + X[ 4] + 0xf57c0faf, S11) + b;
       d = rotateLeft(d + F(a, b, c) + X[ 5] + 0x4787c62a, S12) + a;
       c = rotateLeft(c + F(d, a, B) + X[ 6] + 0xa8304613, S13) + d;
       b = rotateLeft(b + F(c, d, a) + X[ 7] + 0xfd469501, S14) + c;
       a = rotateLeft(a + F(b, c, d) + X[ 8] + 0x698098d8, S11) + b;
       d = rotateLeft(d + F(a, b, c) + X[ 9] + 0x8b44f7af, S12) + a;
       c = rotateLeft(c + F(d, a, B) + X[10] + 0xffff5bb1, S13) + d;
       b = rotateLeft(b + F(c, d, a) + X[11] + 0x895cd7be, S14) + c;
       a = rotateLeft(a + F(b, c, d) + X[12] + 0x6b901122, S11) + b;
       d = rotateLeft(d + F(a, b, c) + X[13] + 0xfd987193, S12) + a;
       c = rotateLeft(c + F(d, a, B) + X[14] + 0xa679438e, S13) + d;
       b = rotateLeft(b + F(c, d, a) + X[15] + 0x49b40821, S14) + c;

       //
       // Round 2 - G cycle, 16 times.
       //
       a = rotateLeft(a + G(b, c, d) + X[ 1] + 0xf61e2562, S21) + b;
       d = rotateLeft(d + G(a, b, c) + X[ 6] + 0xc040b340, S22) + a;
       c = rotateLeft(c + G(d, a, B) + X[11] + 0x265e5a51, S23) + d;
       b = rotateLeft(b + G(c, d, a) + X[ 0] + 0xe9b6c7aa, S24) + c;
       a = rotateLeft(a + G(b, c, d) + X[ 5] + 0xd62f105d, S21) + b;
       d = rotateLeft(d + G(a, b, c) + X[10] + 0x02441453, S22) + a;
       c = rotateLeft(c + G(d, a, B) + X[15] + 0xd8a1e681, S23) + d;
       b = rotateLeft(b + G(c, d, a) + X[ 4] + 0xe7d3fbc8, S24) + c;
       a = rotateLeft(a + G(b, c, d) + X[ 9] + 0x21e1cde6, S21) + b;
       d = rotateLeft(d + G(a, b, c) + X[14] + 0xc33707d6, S22) + a;
       c = rotateLeft(c + G(d, a, B) + X[ 3] + 0xf4d50d87, S23) + d;
       b = rotateLeft(b + G(c, d, a) + X[ 8] + 0x455a14ed, S24) + c;
       a = rotateLeft(a + G(b, c, d) + X[13] + 0xa9e3e905, S21) + b;
       d = rotateLeft(d + G(a, b, c) + X[ 2] + 0xfcefa3f8, S22) + a;
       c = rotateLeft(c + G(d, a, B) + X[ 7] + 0x676f02d9, S23) + d;
       b = rotateLeft(b + G(c, d, a) + X[12] + 0x8d2a4c8a, S24) + c;

       //
       // Round 3 - H cycle, 16 times.
       //
       a = rotateLeft(a + H(b, c, d) + X[ 5] + 0xfffa3942, S31) + b;
       d = rotateLeft(d + H(a, b, c) + X[ 8] + 0x8771f681, S32) + a;
       c = rotateLeft(c + H(d, a, B) + X[11] + 0x6d9d6122, S33) + d;
       b = rotateLeft(b + H(c, d, a) + X[14] + 0xfde5380c, S34) + c;
       a = rotateLeft(a + H(b, c, d) + X[ 1] + 0xa4beea44, S31) + b;
       d = rotateLeft(d + H(a, b, c) + X[ 4] + 0x4bdecfa9, S32) + a;
       c = rotateLeft(c + H(d, a, B) + X[ 7] + 0xf6bb4b60, S33) + d;
       b = rotateLeft(b + H(c, d, a) + X[10] + 0xbebfbc70, S34) + c;
       a = rotateLeft(a + H(b, c, d) + X[13] + 0x289b7ec6, S31) + b;
       d = rotateLeft(d + H(a, b, c) + X[ 0] + 0xeaa127fa, S32) + a;
       c = rotateLeft(c + H(d, a, B) + X[ 3] + 0xd4ef3085, S33) + d;
       b = rotateLeft(b + H(c, d, a) + X[ 6] + 0x04881d05, S34) + c;
       a = rotateLeft(a + H(b, c, d) + X[ 9] + 0xd9d4d039, S31) + b;
       d = rotateLeft(d + H(a, b, c) + X[12] + 0xe6db99e5, S32) + a;
       c = rotateLeft(c + H(d, a, B) + X[15] + 0x1fa27cf8, S33) + d;
       b = rotateLeft(b + H(c, d, a) + X[ 2] + 0xc4ac5665, S34) + c;

       //
       // Round 4 - K cycle, 16 times.
       //
       a = rotateLeft(a + K(b, c, d) + X[ 0] + 0xf4292244, S41) + b;
       d = rotateLeft(d + K(a, b, c) + X[ 7] + 0x432aff97, S42) + a;
       c = rotateLeft(c + K(d, a, B) + X[14] + 0xab9423a7, S43) + d;
       b = rotateLeft(b + K(c, d, a) + X[ 5] + 0xfc93a039, S44) + c;
       a = rotateLeft(a + K(b, c, d) + X[12] + 0x655b59c3, S41) + b;
       d = rotateLeft(d + K(a, b, c) + X[ 3] + 0x8f0ccc92, S42) + a;
       c = rotateLeft(c + K(d, a, B) + X[10] + 0xffeff47d, S43) + d;
       b = rotateLeft(b + K(c, d, a) + X[ 1] + 0x85845dd1, S44) + c;
       a = rotateLeft(a + K(b, c, d) + X[ 8] + 0x6fa87e4f, S41) + b;
       d = rotateLeft(d + K(a, b, c) + X[15] + 0xfe2ce6e0, S42) + a;
       c = rotateLeft(c + K(d, a, B) + X[ 6] + 0xa3014314, S43) + d;
       b = rotateLeft(b + K(c, d, a) + X[13] + 0x4e0811a1, S44) + c;
       a = rotateLeft(a + K(b, c, d) + X[ 4] + 0xf7537e82, S41) + b;
       d = rotateLeft(d + K(a, b, c) + X[11] + 0xbd3af235, S42) + a;
       c = rotateLeft(c + K(d, a, B) + X[ 2] + 0x2ad7d2bb, S43) + d;
       b = rotateLeft(b + K(c, d, a) + X[ 9] + 0xeb86d391, S44) + c;

       H1 += a;
       H2 += b;
       H3 += c;
       H4 += d;

       //
       // reset the offset and clean out the word buffer.
       //
       xOff = 0;
       for (int i = 0; i != X.length; i++)
       {
           X[i] = 0;
       }
   }
}

/**
* base implementation of MD4 family style digest as outlined in
* "Handbook of Applied Cryptography", pages 344 - 347.
*
* @version $Id: GeneralDigest.java,v 1.2 2004/06/27 17:00:55 bheineman Exp $
*/
abstract class GeneralDigest
//    implements Digest - mdb: we don't care about this interface
{
   private byte[]  xBuf;
   private int     xBufOff;

   private long    byteCount;

 /**
  * Standard constructor
  */
 protected GeneralDigest()
 {
   xBuf = new byte[4];
   xBufOff = 0;
 }

 /**
  * Copy constructor.  We are using copy constructors in place
  * of the Object.clone() interface as this interface is not
  * supported by J2ME.
  */
 protected GeneralDigest(GeneralDigest t)
 {
       xBuf = new byte[t.xBuf.length];
   System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);

   xBufOff = t.xBufOff;
   byteCount = t.byteCount;
 }

   public void update(
       byte in)
   {
       xBuf[xBufOff++] = in;

       if (xBufOff == xBuf.length)
       {
           processWord(xBuf, 0);
           xBufOff = 0;
       }

       byteCount++;
   }

   public void update(
       byte[]  in,
       int     inOff,
       int     len)
   {
       //
       // fill the current word
       //
       while ((xBufOff != 0) && (len > 0))
       {
           update(in[inOff]);

           inOff++;
           len--;
       }

       //
       // process whole words.
       //
       while (len > xBuf.length)
       {
           processWord(in, inOff);

           inOff += xBuf.length;
           len -= xBuf.length;
           byteCount += xBuf.length;
       }

       //
       // load in the remainder.
       //
       while (len > 0)
       {
           update(in[inOff]);

           inOff++;
           len--;
       }
   }

   public void finish()
   {
       long    bitLength = (byteCount << 3);

       //
       // add the pad bytes.
       //
       update((byte)128);

       while (xBufOff != 0)
       {
           update((byte)0);
       }

       processLength(bitLength);

       processBlock();
   }

   public void reset()
   {
       byteCount = 0;

       xBufOff = 0;
   for ( int i = 0; i < xBuf.length; i++ ) {
     xBuf[i] = 0;
   }
   }

   protected abstract void processWord(byte[] in, int inOff);

   protected abstract void processLength(long bitLength);

   protected abstract void processBlock();
}

   @Action
   public void LOGIN() {

try {

String driverName = "org.gjt.mm.mysql.Driver";
Class.forName(driverName);
// Create a connection to the database
String id_BD = "gest";
String IP = "127.0.0.1";
String URL = "jdbc:mysql://" + IP + "/" + id_BD;
String username = "root";
String password = "123456";
conn = DriverManager.getConnection(URL, username, password);
} catch (ClassNotFoundException e) {
System.out.println("Erro no driver de ligação:"+e.getMessage());
} catch (SQLException e) {
System.out.println("Erro de SQL:"+e.getMessage());
}
try {
       Statement stmt = conn.createStatement();
       String user="";
       String pass="";
       user=this.USERNAME.getText();
       pass=this.PASSWORD.getText();
String query = "SELECT password FROM user where username='"+user+"';";
       ResultSet rset = stmt.executeQuery(query);
       if(rset.next()){
       if(rset.getString(1).equals(pass)){

this.MENUPRINCIPAL.setVisible(true);
this.MENUPRINCIPAL.setSize(434, 336);
this.MENUPRINCIPAL.setBounds(300, 400, 300, 200);
this.getFrame().setVisible(false);
}
else{
  this.ERRO.setVisible(true);
this.ERRO.setSize(648, 558);
   this.getFrame().setVisible(false);
}
       }
       else{
        this.ERRO.setVisible(true);
this.ERRO.setSize(648, 558);
   this.getFrame().setVisible(false);
       }

       }
catch (Exception e){
this.ERROConection.setVisible(true);
this.ERROConection.setSize(400, 300);
System.out.println("Erro Ao executar a query: "+ e.getMessage());
}
   }

   @Action
   public void VOLTAR() {
    this.ERRO.setVisible(false);
this.getFrame().setVisible(true);
   }

   @Action
   public void OK() {
      this.ERROConection.setVisible(false);
this.getFrame().setVisible(true);
   }

   @Action
   public void REGISTO() {
this.REGISTO.setVisible(true);
this.REGISTO.setSize(449, 370);
this.getFrame().setVisible(false);
   }

   @Action
   public void Registarutilizador() {

long telefone,nif,bi;
String user, nome,morada,/*pass*/mail;
int ip=1;
int data=111;
int tipo=1;
String pass ="pass";

// We have to parse the text to a type float.
   user =String.format(novoutilizador.getText());
   pass = String.format(novapassword.getText());
   mail= String.format(novomail.getText());
   nome=String.format(novo_nome_utilizador.getText());
   morada =String.format(Morada.getText());
   nif = Long.parseLong(Nif.getText());
   bi= Long.parseLong(BI.getText());
   telefone=Long.parseLong(Telefone.getText());


try {
String driverName = "org.gjt.mm.mysql.Driver";
Class.forName(driverName);
// Create a connection to the database
String id_BD = "gest";
String IP = "127.0.0.1";
String URL = "jdbc:mysql://" + IP + "/" + id_BD;
String username = "root";
String password = "123456";
conn = DriverManager.getConnection(URL, username, password);
} catch (ClassNotFoundException e) {
System.out.println("Erro no driver de ligação:"+e.getMessage());
} catch (SQLException e) {
System.out.println("Erro de SQL:"+e.getMessage());
}
  try  {

      MessageDigest md = MessageDigest.getInstance("MD5");

 md.update(pass.getBytes());
 BigInteger hash = new BigInteger(1, md.digest());
 String passCriptografada = hash.toString(16);
} catch(NoSuchAlgorithmException ex)  {
 ex.printStackTrace();
}
try {
Statement stmt = conn.createStatement();
String query="Insert into user (Username,password,email,Nome,Morada,Nif,BI,Telefone,ip,Data,tipo) VALUES('"+user+"','"+pass+"','"+mail+"','"+nome+"','"+morada+"','"+nif+"','"+bi+"','"+telefone+"','"+ip+"','"+data+"','"+tipo+"');";
System.out.println(""+query);
int rest = stmt.executeUpdate(query);

if (rest==0){
System.out.println("REst deu o");
//Registocompleto janela = new Registocompleto();
//janela.setVisible(true);
//this.getFrames()setVisible(false);
}

}
catch (Exception e){
System.out.println("Erro Ao executar a query: "+ e.getMessage());
}

   }





   // Variables declaration - do not modify
   private javax.swing.JTextField BI;
   private javax.swing.JFrame ERRO;
   private javax.swing.JFrame ERROConection;
   private javax.swing.JFrame MENUPRINCIPAL;
   private javax.swing.JTextField Morada;
   private javax.swing.JTextField Nif;
   private javax.swing.JPasswordField PASSWORD;
   private javax.swing.JFrame REGISTO;
   private javax.swing.JTextField Telefone;
   private javax.swing.JTextField USERNAME;
   private javax.swing.JButton jButton1;
   private javax.swing.JButton jButton2;
   private javax.swing.JButton jButton3;
   private javax.swing.JButton jButton4;
   private javax.swing.JButton jButton5;
   private javax.swing.JButton jButton6;
   private javax.swing.JButton jButton7;
   private javax.swing.JButton jButton8;
   private javax.swing.JComboBox jComboBox1;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JLabel jLabel10;
   private javax.swing.JLabel jLabel11;
   private javax.swing.JLabel jLabel12;
   private javax.swing.JLabel jLabel13;
   private javax.swing.JLabel jLabel14;
   private javax.swing.JLabel jLabel15;
   private javax.swing.JLabel jLabel2;
   private javax.swing.JLabel jLabel3;
   private javax.swing.JLabel jLabel4;
   private javax.swing.JLabel jLabel5;
   private javax.swing.JLabel jLabel6;
   private javax.swing.JLabel jLabel7;
   private javax.swing.JLabel jLabel8;
   private javax.swing.JLabel jLabel9;
   private javax.swing.JPanel mainPanel;
   private javax.swing.JMenuBar menuBar;
   private javax.swing.JPasswordField novapassword;
   private javax.swing.JTextField novo_nome_utilizador;
   private javax.swing.JTextField novomail;
   private javax.swing.JTextField novoutilizador;
   private javax.swing.JProgressBar progressBar;
   private javax.swing.JLabel statusAnimationLabel;
   private javax.swing.JLabel statusMessageLabel;
   private javax.swing.JPanel statusPanel;
   // End of variables declaration

   private final Timer messageTimer;
   private final Timer busyIconTimer;
   private final Icon idleIcon;
   private final Icon[] busyIcons = new Icon[15];
   private int busyIconIndex = 0;

   private JDialog aboutBox;
}

Share this post


Link to post
Share on other sites

Poxa cara! Desculpe-me, mas parece até brincadeira. Como você quer salvar a senha criptografada se você faz a criptografia, salva numa variável local com escopo dentro do bloco try e depois manda salvar a String que não foi criptografada?

 

try  {

      MessageDigest md = MessageDigest.getInstance("MD5");

 md.update(pass.getBytes());
 BigInteger hash = new BigInteger(1, md.digest());
 String passCriptografada = hash.toString(16); // ERRADO
} catch(NoSuchAlgorithmException ex)  {
 ex.printStackTrace();
}
try {
Statement stmt = conn.createStatement();
String query="Insert into user (Username,password,email,Nome,Morada,Nif,BI,Telefone,ip,Data,tipo)
VALUES('"+user+"','"+pass+"','"+mail+"','"+nome+"','"+morada+"','"+nif+"','"+bi+
"','"+telefone+"','"+ip+"','"+data+"','"+tipo+"');"; // ERRADO
System.out.println(""+query);
int rest = stmt.executeUpdate(query);

 

Solução:

try {
  ...
  pass = hash.toString(16);
} catch (NoSuchAlgorithmException ex) {
  ...
}

...
String query="Insert into user (Username,password,email,Nome,Morada,Nif,BI,Telefone,ip,Data,tipo) VALUES('"+user+"','"+pass+"','"+mail+"','"+nome+"','"+morada+"','"+nif+"','"+bi+"','"+telefone+"','"+ip+"','"+data+"','"+tipo+"');";
...

 

Dica: Se tiver que usar realmente JDBC diretamente, tente ao menos utilizar o PreparedStatement. Deixará seu código menos confuso.

Share this post


Link to post
Share on other sites

Dá uma pesquisada na API java.net . Pois o que vou lhe passar é muito superficial.

 

try {  
  InetAddress inetAddres = InetAddress.getLocalHost();  
  System.out.println("Endereço IP : " + inetAddres.getHostAddress());  
} catch (UnknownHostException ex) {  
  ex.printStackTrace();  
}

Share this post


Link to post
Share on other sites

Você terá uma tabela pra armazenar os salt numbers. Quando o usuário cadastrar uma senha. Você gera de preferência aleatoriamente um salt number e depois gera o hash da senha mais o salt number. Sempre que o usuário fizer login você terá que buscar na base o salt number dele adicionar à senha e gerar o hash para depois verificar se o hash gerado é o mesmo que está salvo na base.

Share this post


Link to post
Share on other sites

Aqui tem um exemplo de modelagem http://forum.imasters.com.br/topic/403237-construindo-uma-rede-social-iniciando-o-projeto/

E aqui tem um artigo sobre armazenamento de senhas com salt number http://www.vivaolinux.com.br/artigo/Armazenamento-de-senhas-no-Linux/?pagina=7

 

Agora você implementa. <_<

Share this post


Link to post
Share on other sites

como faço para mostrar os dados que estão increptados mas não os quero mostrar incriptados mas sim desincreptados

Share this post


Link to post
Share on other sites

Não é possível desencriptar um hash MD5.

Share this post


Link to post
Share on other sites

o meu md5 esta a 128 bits

como eu passo para 512 bits

 

ja criei a tabela salt

agora tenho que fazer o mesmo que fiz para o md5 so que vez de se chamar md5 chama-se salt


try  {

      MessageDigest md = MessageDigest.getInstance("MD5");

 md.update(pass.getBytes());
 BigInteger hash = new BigInteger(1, md.digest());
pass = hash.toString(16);
} catch(NoSuchAlgorithmException ex)  {
 ex.printStackTrace();
}

isto não esta facil

 

 /*public static void main(String args[]) throws Exception {
   String user = "user";
   String passwd = "password";
   String salts = "12,12,12";

   String salttmp[] = salts.split(",");
   byte salt[] = new byte[salttmp.length];

   for (int i = 0; i < salt.length; i++) {
     salt[i] = Byte.parseByte(salttmp[i]);
   }
   MessageDigest m = MessageDigest.getInstance("MD5");
   m.update(salt);
   m.update("user".getBytes("UTF8"));
   byte s[] = m.digest();
   String result = "";
   for (int i = 0; i < s.length; i++) {
     result += Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6);
   }
   System.out.println(result.equals(passwd));
 }

e este codigo tem que polo quer no registo quer no login como na recuperação da pass

ou seja tenho que por onde os dados são incriptados

e tenho que por a gravar na base de dados

certo

diz-me a onde me estou errar

Share this post


Link to post
Share on other sites

Por que você está criptografando o salt number?

 

Você tem que juntar a senha com o salt number pra depois gerar o hash.

 

Ex.:

Senha = teste

Salt number = 123

Valor a ser criptografado = teste123

Share this post


Link to post
Share on other sites

×

Important Information

Ao usar o fórum, você concorda com nossos Terms of Use.