Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void displayLoadScreen() {
- if(!hasSaved){
- String userName = JOptionPane.showInputDialog(
- null, "Enter your username:", "John Doe_123");
- String passWord = JOptionPane.showInputDialog(
- null, "Enter your password:", "jdpassword123");
- try {
- File file = (new File("CubeCrasherFiles\\" + userName + ".ccf"));
- if(file.exists()){
- Scanner inFile = new Scanner(file);
- String test = inFile.nextLine();
- String input = encryptBlowfish(passWord, passWord);
- //FIX:
- if(test.equals(encryptBlowfish(input,input))){
- System.out.println("reading");
- CubeWorld c = (CubeWorld)this.getWorld();
- LevelLoader l = c.getSystem().getLevelLoader();
- l.empty();
- int score = inFile.nextInt();
- int level = inFile.nextInt();
- c.getSystem().setScore(score);
- c.getSystem().setLevel(level);
- l.fill(level);
- }
- inFile.close();
- file.renameTo(new File("CubeCrasherFiles\\resid_" + Math.random()*123983098 + ".ccf"));
- hasSaved = true;
- }else{
- JOptionPane.showMessageDialog(null, "Username/Password does not exist",
- "Error!", 0, new ImageIcon("Images\\CubeCrasher.jpg"));
- }
- } catch(Exception e) {
- // TODO Auto-generated catch block
- System.out.println(e);
- }
- AudioClip aClip = null;
- URL bing = null;
- try {
- bing = new File("Sounds\\LoadModulus.wav").toURI().toURL();
- } catch (MalformedURLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- aClip = Applet.newAudioClip(bing);
- aClip.play();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- JOptionPane.showMessageDialog(null, "You have already saved/loaded a session",
- "Error!", 0, new ImageIcon("Images\\CubeCrasher.jpg"));
- }
- public static String encryptBlowfish(String to_encrypt, String strkey){
- try{
- System.out.println(to_encrypt.length());
- SecretKeySpec key = new SecretKeySpec(strkey.getBytes(), "Blowfish");
- Cipher cipher = Cipher.getInstance("Blowfish");
- cipher.init(Cipher.ENCRYPT_MODE, key);
- byte[] decrypted = cipher.doFinal(to_encrypt.getBytes());
- return new String(decrypted);
- }catch(Exception e){return null;}
- }
Add Comment
Please, Sign In to add comment