Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft;
- import java.awt.*;
- import java.io.*;
- import java.util.Random;
- import javax.crypto.*;
- import javax.crypto.spec.PBEKeySpec;
- import javax.crypto.spec.PBEParameterSpec;
- import javax.swing.*;
- import javax.swing.border.MatteBorder;
- // Referenced classes of package net.minecraft:
- // TransparentPanel, TransparentCheckbox, TransparentButton, TransparentLabel,
- // Util, TexturedPanel, LogoPanel, LauncherFrame
- public class LoginForm extends TransparentPanel
- {
- public LoginForm(LauncherFrame launcherFrame)
- {
- userName = new jtextfield(20);
- password = new jpasswordfield(20);
- rememberBox = new TransparentCheckbox("Remember password");
- launchButton = new TransparentButton("Login");
- optionsButton = new TransparentButton("Options");
- retryButton = new TransparentButton("Try again");
- offlineButton = new TransparentButton("Play offline");
- errorLabel = new TransparentLabel("", 0);
- outdated = false;
- this.launcherFrame = launcherFrame;
- borderlayout gbl = new borderlayout();
- setLayout(gbl);
- add(buildMainLoginPanel(), "Center");
- readUsername();
- java.awt.event.actionlistener al = new object() /* anonymous class not found */
- class _anm1 {}
- ;
- userName.addActionListener(al);
- password.addActionListener(al);
- retryButton.addActionListener(new object() /* anonymous class not found */
- class _anm2 {}
- );
- offlineButton.addActionListener(new object(launcherFrame) /* anonymous class not found */
- class _anm3 {}
- );
- launchButton.addActionListener(al);
- optionsButton.addActionListener(new object(launcherFrame) /* anonymous class not found */
- class _anm4 {}
- );
- }
- public void doLogin()
- {
- setLoggingIn();
- (new object() /* anonymous class not found */
- class _anm5 {}
- ).start();
- }
- private void readUsername()
- {
- try
- {
- file lastLogin = new file(util.getWorkingDirectory(), "lastlogin");
- Cipher cipher = getCipher(2, "passwordfile");
- datainputstream dis;
- if(cipher != null)
- dis = new datainputstream(new CipherInputStream(new fileinputstream(lastLogin), cipher));
- else
- dis = new datainputstream(new fileinputstream(lastLogin));
- userName.setText(dis.readUTF());
- password.setText(dis.readUTF());
- rememberBox.setSelected(password.getPassword().length > 0);
- dis.close();
- }
- catch(exception e)
- {
- e.printStackTrace();
- }
- }
- private void writeUsername()
- {
- try
- {
- file lastLogin = new file(util.getWorkingDirectory(), "lastlogin");
- Cipher cipher = getCipher(1, "passwordfile");
- dataoutputstream dos;
- if(cipher != null)
- dos = new dataoutputstream(new CipherOutputStream(new fileoutputstream(lastLogin), cipher));
- else
- dos = new dataoutputstream(new fileoutputstream(lastLogin));
- dos.writeUTF(userName.getText());
- dos.writeUTF(rememberBox.isSelected() ? new string(password.getPassword()) : "");
- dos.close();
- }
- catch(exception e)
- {
- e.printStackTrace();
- }
- }
- private Cipher getCipher(int mode, string password)
- throws exception
- {
- random random = new random(0x29482c2L);
- byte salt[] = new byte[8];
- random.nextBytes(salt);
- PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
- javax.crypto.SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
- Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
- cipher.init(mode, pbeKey, pbeParamSpec);
- return cipher;
- }
- private jscrollpane getUpdateNews()
- {
- if(scrollPane != null)
- return scrollPane;
- try
- {
- jtextpane editorPane = new object() /* anonymous class not found */
- class _anm6 {}
- ;
- editorPane.setText("<html><body><font color=\"#808080\"><br><br><br><br><br><br><br><center>Loading update news..</center></font></body></html>");
- editorPane.addHyperlinkListener(new object() /* anonymous class not found */
- class _anm7 {}
- );
- (new object(editorPane) /* anonymous class not found */
- class _anm8 {}
- ).start();
- editorPane.setBackground(color.DARK_GRAY);
- editorPane.setEditable(false);
- scrollPane = new jscrollpane(editorPane);
- scrollPane.setBorder(null);
- editorPane.setMargin(null);
- scrollPane.setBorder(new matteborder(0, 0, 2, 0, color.BLACK));
- }
- catch(exception e2)
- {
- e2.printStackTrace();
- }
- return scrollPane;
- }
- private jpanel buildMainLoginPanel()
- {
- jpanel p = new TransparentPanel(new borderlayout());
- p.add(getUpdateNews(), "Center");
- jpanel southPanel = new TexturedPanel();
- southPanel.setLayout(new borderlayout());
- southPanel.add(new LogoPanel(), "West");
- southPanel.add(new TransparentPanel(), "Center");
- southPanel.add(center(buildLoginPanel()), "East");
- southPanel.setPreferredSize(new dimension(100, 100));
- p.add(southPanel, "South");
- return p;
- }
- private jpanel buildLoginPanel()
- {
- TransparentPanel panel = new TransparentPanel();
- panel.setInsets(4, 0, 4, 0);
- borderlayout layout = new borderlayout();
- layout.setHgap(0);
- layout.setVgap(8);
- panel.setLayout(layout);
- gridlayout gl1 = new gridlayout(0, 1);
- gl1.setVgap(2);
- gridlayout gl2 = new gridlayout(0, 1);
- gl2.setVgap(2);
- gridlayout gl3 = new gridlayout(0, 1);
- gl3.setVgap(2);
- TransparentPanel titles = new TransparentPanel(gl1);
- TransparentPanel values = new TransparentPanel(gl2);
- titles.add(new TransparentLabel("Username:", 4));
- titles.add(new TransparentLabel("Password:", 4));
- titles.add(new TransparentLabel("", 4));
- values.add(userName);
- values.add(password);
- values.add(rememberBox);
- panel.add(titles, "West");
- panel.add(values, "Center");
- TransparentPanel loginPanel = new TransparentPanel(new borderlayout());
- TransparentPanel third = new TransparentPanel(gl3);
- titles.setInsets(0, 0, 0, 4);
- third.setInsets(0, 10, 0, 10);
- third.add(optionsButton);
- third.add(launchButton);
- try
- {
- if(outdated)
- {
- TransparentLabel accountLink = getUpdateLink();
- third.add(accountLink);
- } else
- {
- TransparentLabel accountLink = new object("Need account?") /* anonymous class not found */
- class _anm9 {}
- ;
- accountLink.setCursor(cursor.getPredefinedCursor(12));
- accountLink.addMouseListener(new object() /* anonymous class not found */
- class _anm10 {}
- );
- accountLink.setForeground(LINK_COLOR);
- third.add(accountLink);
- }
- }
- catch(error error) { }
- loginPanel.add(third, "Center");
- panel.add(loginPanel, "East");
- errorLabel.setFont(new font(null, 2, 16));
- errorLabel.setForeground(new color(0xff4040));
- errorLabel.setText("");
- panel.add(errorLabel, "North");
- return panel;
- }
- private TransparentLabel getUpdateLink()
- {
- TransparentLabel accountLink = new object("You need to update the launcher!") /* anonymous class not found */
- class _anm11 {}
- ;
- accountLink.setCursor(cursor.getPredefinedCursor(12));
- accountLink.addMouseListener(new object() /* anonymous class not found */
- class _anm12 {}
- );
- accountLink.setForeground(LINK_COLOR);
- return accountLink;
- }
- private jpanel buildMainOfflinePanel()
- {
- jpanel p = new TransparentPanel(new borderlayout());
- p.add(getUpdateNews(), "Center");
- jpanel southPanel = new TexturedPanel();
- southPanel.setLayout(new borderlayout());
- southPanel.add(new LogoPanel(), "West");
- southPanel.add(new TransparentPanel(), "Center");
- southPanel.add(center(buildOfflinePanel()), "East");
- southPanel.setPreferredSize(new dimension(100, 100));
- p.add(southPanel, "South");
- return p;
- }
- private component center(component c)
- {
- TransparentPanel tp = new TransparentPanel(new gridbaglayout());
- tp.add(c);
- return tp;
- }
- private TransparentPanel buildOfflinePanel()
- {
- TransparentPanel panel = new TransparentPanel();
- panel.setInsets(0, 0, 0, 20);
- borderlayout layout = new borderlayout();
- panel.setLayout(layout);
- TransparentPanel loginPanel = new TransparentPanel(new borderlayout());
- gridlayout gl = new gridlayout(0, 1);
- gl.setVgap(2);
- TransparentPanel pp = new TransparentPanel(gl);
- pp.setInsets(0, 8, 0, 0);
- pp.add(retryButton);
- pp.add(offlineButton);
- loginPanel.add(pp, "East");
- boolean canPlayOffline = launcherFrame.canPlayOffline(userName.getText());
- offlineButton.setEnabled(canPlayOffline);
- if(!canPlayOffline)
- loginPanel.add(new TransparentLabel("(Not downloaded)", 4), "South");
- panel.add(loginPanel, "Center");
- TransparentPanel p2 = new TransparentPanel(new gridlayout(0, 1));
- errorLabel.setFont(new font(null, 2, 16));
- errorLabel.setForeground(new color(0xff4040));
- p2.add(errorLabel);
- if(outdated)
- {
- TransparentLabel accountLink = getUpdateLink();
- p2.add(accountLink);
- }
- loginPanel.add(p2, "Center");
- return panel;
- }
- public void setError(string errorMessage)
- {
- removeAll();
- add(buildMainLoginPanel(), "Center");
- errorLabel.setText(errorMessage);
- validate();
- }
- public void loginOk()
- {
- writeUsername();
- }
- public void setLoggingIn()
- {
- removeAll();
- jpanel panel = new jpanel(new borderlayout());
- panel.add(getUpdateNews(), "Center");
- jpanel southPanel = new TexturedPanel();
- southPanel.setLayout(new borderlayout());
- southPanel.add(new LogoPanel(), "West");
- southPanel.add(new TransparentPanel(), "Center");
- jlabel label = new TransparentLabel("Logging in... ", 0);
- label.setFont(new font(null, 1, 16));
- southPanel.add(center(label), "East");
- southPanel.setPreferredSize(new dimension(100, 100));
- panel.add(southPanel, "South");
- add(panel, "Center");
- validate();
- }
- public void setNoNetwork()
- {
- removeAll();
- add(buildMainOfflinePanel(), "Center");
- validate();
- }
- public void checkAutologin()
- {
- if(password.getPassword().length > 0)
- launcherFrame.login(userName.getText(), new string(password.getPassword()));
- }
- public void setOutdated()
- {
- outdated = true;
- }
- private static final int PANEL_SIZE = 100;
- private static final long serialVersionUID = 1L;
- private static final color LINK_COLOR = new color(0x8080ff);
- public jtextfield userName;
- public jpasswordfield password;
- private TransparentCheckbox rememberBox;
- private TransparentButton launchButton;
- private TransparentButton optionsButton;
- private TransparentButton retryButton;
- private TransparentButton offlineButton;
- private TransparentLabel errorLabel;
- private LauncherFrame launcherFrame;
- private boolean outdated;
- private jscrollpane scrollPane;
- }
Add Comment
Please, Sign In to add comment