⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logon.java

📁 QQ聊天工具的源代码
💻 JAVA
字号:
/*
 * logon.java
 *
 * Created on 2007年12月19日, 下午7:55
 */

/**
 *
 * @author  Admin
 */
import java.io.*;
import java.net.*;
import javax.swing.*;
public class logon extends javax.swing.JFrame {
	public static Socket clientskt= null;
//*************************************************************************************************************************
	private static String rsaN = "BE211D1627D0FA0EDE557CB342256C9B6B7CEDB5A727BF732499393428EF2EC8704ADE733C65B234" +
                           "0B9C1DA282A57EC3B8352D6382E3DC32951EE741181A60FF";
	private static String rsaD = "463367CFF4679ECCBA9F09EA0E344F439B8E871E99577DC2FFF26B42AD12934CDE8A43617F97D277" +
                           "F856A42EA37D9936A2CE81351A432EB9B8A4DF818DA506F1";//D,N public key
	private static String rsaE = "10001";//E,N private key  
//*************************************************************************************************************************
	/** Creates new form logon */
	public logon() {
		initComponents();
	}
	/** 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.
	 */
        // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
        private void initComponents() {
                logonLable = new javax.swing.JLabel();
                usernameTF = new javax.swing.JTextField();
                usernameLable = new javax.swing.JLabel();
                newNameBtn = new javax.swing.JButton();
                passwordLable = new javax.swing.JLabel();
                logonBtn = new javax.swing.JButton();
                usernameExplainLable = new javax.swing.JLabel();
                passwordExplainLable = new javax.swing.JLabel();
                passwordJPF = new javax.swing.JPasswordField();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                setTitle("SuperWhisper beta1");
                setResizable(false);
                logonLable.setText("Log on");

                usernameLable.setText("Username");

                newNameBtn.setText("new user");
                newNameBtn.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                newNameBtnActionPerformed(evt);
                        }
                });

                passwordLable.setText("Password");

                logonBtn.setText("log on");
                logonBtn.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                logonBtnActionPerformed(evt);
                        }
                });

                usernameExplainLable.setText("characters and numbers only and 8 at most");

                passwordExplainLable.setText("characters and numbers only and 10 at most");

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(314, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(logonBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(newNameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(24, 24, 24))
                        .addGroup(layout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(passwordLable)
                                        .addComponent(passwordExplainLable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(logonLable, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(usernameLable, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(usernameTF)
                                        .addComponent(usernameExplainLable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(passwordJPF))
                                .addGap(150, 150, 150))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(logonLable)
                                .addGap(27, 27, 27)
                                .addComponent(usernameLable)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(usernameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(usernameExplainLable)
                                .addGap(17, 17, 17)
                                .addComponent(passwordLable)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(passwordJPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(passwordExplainLable)
                                .addGap(10, 10, 10)
                                .addComponent(logonBtn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(newNameBtn)
                                .addContainerGap())
                );
                pack();
        }// </editor-fold>//GEN-END:initComponents

	private void request()					//与注册窗口的request函数相同;
	{
		try{
			clientskt = new Socket("127.0.0.1", 2000);
			DataOutputStream dos = new DataOutputStream(clientskt.getOutputStream());
			dos.writeBytes("1");
			dos.close();
			clientskt.close();
		}catch(UnknownHostException uhex)
		{
			System.err.println(uhex);
		}catch(IOException ioex)
		{
			System.err.println(ioex);
		}
	}
	private String receive()				//与注册窗口的receive函数相同;
	{
		String recString = "";
		try{
			clientskt = new Socket("127.0.0.1", 2001);
			BufferedReader binReader = new BufferedReader(new InputStreamReader(clientskt.getInputStream()));
			recString = binReader.readLine();
			binReader.close();
			clientskt.close();
		}catch(UnknownHostException ex){
			System.err.println(ex);
		}catch(IOException ex){
			System.err.println(ex);
		}
		return recString;
	}
	private void logonAndnewuser(int mode, String username, String password, String sessionkey)
	{
		String plaintext = mode+username+"&"+password+"&"+sessionkey;
		String ke = RC4.keyGet();
	        String ciphertext = EncryptAndDecrypt.encryption(plaintext, ke, "RSA");
		try{
			clientskt = new Socket("127.0.0.1", 2000);
			DataOutputStream dos = new DataOutputStream(clientskt.getOutputStream());
			dos.writeBytes(ciphertext);
			dos.close();
			clientskt.close();
		}catch(UnknownHostException uhex)
		{
			System.err.println(uhex);
		}catch(IOException ioex)
		{
			System.err.println(ioex);
		}
	}
	private void newNameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newNameBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		this.setVisible(false);  
		new register().setVisible(true); 
	}//GEN-LAST:event_newNameBtnActionPerformed

	private void logonBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logonBtnActionPerformed
// TODO 将在此处添加您的处理代码:
		String username = usernameTF.getText();
		String password = String.valueOf(passwordJPF.getPassword());
		String ke = RC4.keyGet();
		String mes = "";
		request();
		mes = receive();
		if(mes.equals("1&"+rsaN+"&"+rsaD));
		{
			logonAndnewuser(0, username, password, ke);
		}
		String ciphertext = receive();
		mes = EncryptAndDecrypt.decryption(ciphertext, ke, "RC4");
		if(mes.equals("welcome"))
		{
			this.setVisible(false);
			new clientWindow(username, clientskt.getInetAddress().toString(), ke).setVisible(true);
		}else if(mes.equals("not exist"))
		{
			JOptionPane.showMessageDialog(null,"wrong username or password.", "sorry", JOptionPane.INFORMATION_MESSAGE);
		}
	}//GEN-LAST:event_logonBtnActionPerformed
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new logon().setVisible(true);
			}
		});
	}
	
        // 变量声明 - 不进行修改//GEN-BEGIN:variables
        private javax.swing.JButton logonBtn;
        private javax.swing.JLabel logonLable;
        private javax.swing.JButton newNameBtn;
        private javax.swing.JLabel passwordExplainLable;
        private javax.swing.JPasswordField passwordJPF;
        private javax.swing.JLabel passwordLable;
        private javax.swing.JLabel usernameExplainLable;
        private javax.swing.JLabel usernameLable;
        private javax.swing.JTextField usernameTF;
        // 变量声明结束//GEN-END:variables
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -