Changeset 32
- Timestamp:
- 03/30/07 00:19:54 (2 years ago)
- Files:
-
- trunk/src/org/lastpod/LastPod.java (modified) (2 diffs)
- trunk/src/org/lastpod/MiscUtilities.java (modified) (3 diffs)
- trunk/src/org/lastpod/PreferencesEditor.java (modified) (2 diffs)
- trunk/src/org/lastpod/Scrobbler.java (modified) (3 diffs)
- trunk/src/org/lastpod/UI.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org/lastpod/LastPod.java
r31 r32 92 92 String username = fPrefs.get("Username", "default"); 93 93 String password = fPrefs.get("Password", "default"); 94 String encryptedPassword = fPrefs.get("encryptedPassword", "default"); 94 95 95 if (username.equals("default") && password.equals("default")) { 96 if (!password.equals("default")) { 97 encryptedPassword = MiscUtilities.md5DigestPassword(password); 98 fPrefs.put("encryptedPassword", encryptedPassword); 99 fPrefs.remove("Password"); 100 101 String message = 102 "Your password was stored unencrypted on your system." 103 + " This version of LastPod has encrypted this password for future usage."; 104 JOptionPane.showMessageDialog(UI.getFrame(), message); 105 106 logger = Logger.getLogger(LastPod.class.getPackage().getName()); 107 logger.log(Level.WARNING, message); 108 } 109 110 String encryptedDefault = MiscUtilities.md5DigestPassword("default"); 111 112 if (username.equals("default") && encryptedPassword.equals(encryptedDefault)) { 96 113 logger.log(Level.INFO, LastPod.NoPrefsError); 97 114 … … 100 117 101 118 try { 102 LastPod.scrobbler = new Scrobbler(username, password);119 LastPod.scrobbler = new Scrobbler(username, encryptedPassword); 103 120 104 121 List activeRecentPlayed = onlyActiveTrackItems(recentplayed); trunk/src/org/lastpod/MiscUtilities.java
r29 r32 20 20 package org.lastpod; 21 21 22 import java.security.MessageDigest; 23 import java.security.NoSuchAlgorithmException; 22 24 23 25 /** … … 39 41 * @return A heidecimal String representing the byte array. 40 42 */ 41 public static String hex encode(byte[] array) {43 public static String hexEncode(byte[] array) { 42 44 StringBuffer sb = new StringBuffer(); 43 45 … … 48 50 return sb.toString(); 49 51 } 52 53 /** 54 * Creates a MD5 digest String from a given password. 55 * @param password The password to digest. 56 * @return The MD5 digested password. 57 */ 58 public static String md5DigestPassword(String password) { 59 try { 60 MessageDigest md = MessageDigest.getInstance("MD5"); 61 62 return hexEncode(md.digest(password.getBytes())); 63 } catch (NoSuchAlgorithmException e) { 64 throw new RuntimeException("No MD5 algorithm present on the system"); 65 } 66 } 50 67 } trunk/src/org/lastpod/PreferencesEditor.java
r31 r32 117 117 private void matchPreferences() { 118 118 this.userfield.setText(fPrefs.get("Username", "<Username>")); 119 this.passfield.setText(fPrefs.get("Password", ""));120 119 this.dbfield.setText(fPrefs.get("iTunes Path", "<iPod iTunes Database Location>")); 121 120 } … … 123 122 private void savePreferences() { 124 123 fPrefs.put("Username", this.userfield.getText()); 125 fPrefs.put("Password", new String(this.passfield.getPassword())); 124 125 String password = new String(passfield.getPassword()); 126 127 if (password.length() != 0) { 128 String encryptedPassword = MiscUtilities.md5DigestPassword(password); 129 fPrefs.put("encryptedPassword", encryptedPassword); 130 } 131 126 132 fPrefs.put("iTunes Path", this.dbfield.getText()); 127 133 trunk/src/org/lastpod/Scrobbler.java
r31 r32 52 52 public class Scrobbler { 53 53 private String username; 54 private String password;54 private String encryptedPassword; 55 55 private String challenge; 56 56 private String submithost; … … 59 59 private Logger logger; 60 60 61 public Scrobbler(String username, String password) {61 public Scrobbler(String username, String encryptedPassword) { 62 62 this.username = username; 63 this. password = password;63 this.encryptedPassword = encryptedPassword; 64 64 this.logger = Logger.getLogger(this.getClass().getPackage().getName()); 65 65 } … … 152 152 153 153 MessageDigest md = MessageDigest.getInstance("MD5"); 154 String md5pass = 155 MiscUtilities.hexencode(md.digest(this.password.getBytes())) + this.challenge; 156 String md5chal = MiscUtilities.hexencode(md.digest(md5pass.getBytes())); 154 String md5pass = encryptedPassword + this.challenge; 155 String md5chal = MiscUtilities.hexEncode(md.digest(md5pass.getBytes())); 157 156 158 157 String querystring = trunk/src/org/lastpod/UI.java
r31 r32 41 41 private JTextArea logtextarea; 42 42 private JFrame frame; 43 44 /** 45 * Gets the user interface's JFrame. 46 * @return The user interface's JFrame. 47 */ 48 public JFrame getFrame() { 49 return frame; 50 } 43 51 44 52 public void buildUI() {
