1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
| package net.minecraft;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Rectangle;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.VolatileImage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginForm extends JPanel
{
private int x = 225;
private int y = 10;
private static final long serialVersionUID = 1L;
private Image bgImage;
private JTextField userName;
private JPasswordField password;
private static SpllitButton but = new SpllitButton(0);
private JCheckBox rememberBox = new JCheckBox("Retenir mot de passe");
private JButton launchButton = new JButton("Login");
private JButton offlineButton = new JButton("Jouer hors ligne");
private JEditorPane news = new JEditorPane();
private JButton options = new JButton("Options");
private Label errorLabel = new Label("", 1);
private LauncherFrame launcherFrame;
private boolean outdated = false;
private Image fondtroll = null;
private Image fondoutdate = null;
BufferedImage image = null;
private Music sound_1 = new Music("lol");
public LoginForm()
{
setBackground(Color.black);
setLayout(null);
initMenu();
// playSong(sound_1);
//readUsername();
this.but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (userName.getText().isEmpty() || password.getText().isEmpty())
{
javax.swing.JOptionPane.showMessageDialog(null,"Veuillez compléter les champs requis");
}
else
launcherFrame.login(userName.getText(), password.getText());
}
}
);
}
public void initMenu()
{
try
{
this.bgImage = ImageIO.read(LoginForm.class.getResource("BackgroundLauncher.png"));
} catch (IOException e) {
e.printStackTrace();
}
this.userName = new JTextField(39);
this.userName.setBounds(275, 180, 250, 15);
this.userName.setFocusable(true);
this.userName.setForeground(Color.BLACK);
this.userName.setCaretColor(Color.BLACK);
this.userName.setBorder(BorderFactory.createEmptyBorder());
this.userName.setOpaque(true);
add(this.userName);
this.password = new JPasswordField(39);
this.password.setBounds(275, 214+30, 275, 15);
this.password.setForeground(Color.BLACK);
this.password.setBorder(BorderFactory.createEmptyBorder());
this.password.setFocusable(true);
this.password.setOpaque(true);
add(this.password);
add(this.but);
}
public void playSong(Music sound)
{
sound.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));
}
this.userName.setText(dis.readUTF());
this.password.setText(dis.readUTF());
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(this.userName.getText());
dos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private Cipher getCipher(int mode, String password) throws Exception {
Random random = new Random(43287234L);
byte[] salt = new byte[8];
random.nextBytes(salt);
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(mode, pbeKey, pbeParamSpec);
return cipher;
}
public void update(Graphics g) {
paint(g);
}
Image font;
public void paint(Graphics g2)
{
super.paint(g2);
ImageIcon gif;
int w = getWidth() ;
int h = getHeight() ;
try {
font = ImageIO.read(LoginForm.class.getResource("font.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g2.drawImage(font,0,0,w,h, null);
g2.drawImage(this.bgImage,20+x,50+y, null);
g2.dispose();
}
public void setError(String errorMessage) {
removeAll();
this.errorLabel.setText(errorMessage);
validate();
}
public void loginOk() {
writeUsername();
}
public void setNoNetwork() {
removeAll();
validate();
}
public void checkAutologin() {
if (this.password.getText().length() > 0)
this.launcherFrame.login(this.userName.getText(), this.password.getText());
}
public void setOutdated()
{
this.outdated = true;
}
} |
Partager