Guest User

Untitled

a guest
Jun 28th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. public void displayLoadScreen() {
  2.  
  3. if(!hasSaved){
  4. String userName = JOptionPane.showInputDialog(
  5. null, "Enter your username:", "John Doe_123");
  6. String passWord = JOptionPane.showInputDialog(
  7. null, "Enter your password:", "jdpassword123");
  8. try {
  9. File file = (new File("CubeCrasherFiles\\" + userName + ".ccf"));
  10.  
  11. if(file.exists()){
  12.  
  13. Scanner inFile = new Scanner(file);
  14. String test = inFile.nextLine();
  15. String input = encryptBlowfish(passWord, passWord);
  16.  
  17. //FIX:
  18.  
  19. if(test.equals(encryptBlowfish(input,input))){
  20.  
  21. System.out.println("reading");
  22. CubeWorld c = (CubeWorld)this.getWorld();
  23. LevelLoader l = c.getSystem().getLevelLoader();
  24. l.empty();
  25. int score = inFile.nextInt();
  26. int level = inFile.nextInt();
  27. c.getSystem().setScore(score);
  28. c.getSystem().setLevel(level);
  29. l.fill(level);
  30. }
  31.  
  32. inFile.close();
  33. file.renameTo(new File("CubeCrasherFiles\\resid_" + Math.random()*123983098 + ".ccf"));
  34. hasSaved = true;
  35. }else{
  36.  
  37. JOptionPane.showMessageDialog(null, "Username/Password does not exist",
  38. "Error!", 0, new ImageIcon("Images\\CubeCrasher.jpg"));
  39. }
  40. } catch(Exception e) {
  41. // TODO Auto-generated catch block
  42. System.out.println(e);
  43. }
  44.  
  45. AudioClip aClip = null;
  46. URL bing = null;
  47. try {
  48. bing = new File("Sounds\\LoadModulus.wav").toURI().toURL();
  49. } catch (MalformedURLException e1) {
  50. // TODO Auto-generated catch block
  51. e1.printStackTrace();
  52. }
  53. try {
  54. aClip = Applet.newAudioClip(bing);
  55. aClip.play();
  56. } catch (Exception e) {
  57. // TODO Auto-generated catch block
  58. e.printStackTrace();
  59. }
  60. }else{
  61.  
  62. JOptionPane.showMessageDialog(null, "You have already saved/loaded a session",
  63. "Error!", 0, new ImageIcon("Images\\CubeCrasher.jpg"));
  64. }
  65. public static String encryptBlowfish(String to_encrypt, String strkey){
  66.  
  67. try{
  68.  
  69. System.out.println(to_encrypt.length());
  70. SecretKeySpec key = new SecretKeySpec(strkey.getBytes(), "Blowfish");
  71. Cipher cipher = Cipher.getInstance("Blowfish");
  72. cipher.init(Cipher.ENCRYPT_MODE, key);
  73.  
  74. byte[] decrypted = cipher.doFinal(to_encrypt.getBytes());
  75.  
  76. return new String(decrypted);
  77. }catch(Exception e){return null;}
  78. }
Add Comment
Please, Sign In to add comment