Changeset 32

Show
Ignore:
Timestamp:
03/30/07 00:19:54 (2 years ago)
Author:
chris
Message:

r7531@flan: chris | 2007-03-03 18:12:01 -0800
store the password in encrypted form. I don't know why this wasn't already done

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/org/lastpod/LastPod.java

    r31 r32  
    9292        String username = fPrefs.get("Username", "default"); 
    9393        String password = fPrefs.get("Password", "default"); 
     94        String encryptedPassword = fPrefs.get("encryptedPassword", "default"); 
    9495 
    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)) { 
    96113            logger.log(Level.INFO, LastPod.NoPrefsError); 
    97114 
     
    100117 
    101118        try { 
    102             LastPod.scrobbler = new Scrobbler(username, password); 
     119            LastPod.scrobbler = new Scrobbler(username, encryptedPassword); 
    103120 
    104121            List activeRecentPlayed = onlyActiveTrackItems(recentplayed); 
  • trunk/src/org/lastpod/MiscUtilities.java

    r29 r32  
    2020package org.lastpod; 
    2121 
     22import java.security.MessageDigest; 
     23import java.security.NoSuchAlgorithmException; 
    2224 
    2325/** 
     
    3941     * @return  A heidecimal String representing the byte array. 
    4042     */ 
    41     public static String hexencode(byte[] array) { 
     43    public static String hexEncode(byte[] array) { 
    4244        StringBuffer sb = new StringBuffer(); 
    4345 
     
    4850        return sb.toString(); 
    4951    } 
     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    } 
    5067} 
  • trunk/src/org/lastpod/PreferencesEditor.java

    r31 r32  
    117117    private void matchPreferences() { 
    118118        this.userfield.setText(fPrefs.get("Username", "<Username>")); 
    119         this.passfield.setText(fPrefs.get("Password", "")); 
    120119        this.dbfield.setText(fPrefs.get("iTunes Path", "<iPod iTunes Database Location>")); 
    121120    } 
     
    123122    private void savePreferences() { 
    124123        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 
    126132        fPrefs.put("iTunes Path", this.dbfield.getText()); 
    127133 
  • trunk/src/org/lastpod/Scrobbler.java

    r31 r32  
    5252public class Scrobbler { 
    5353    private String username; 
    54     private String password; 
     54    private String encryptedPassword; 
    5555    private String challenge; 
    5656    private String submithost; 
     
    5959    private Logger logger; 
    6060 
    61     public Scrobbler(String username, String password) { 
     61    public Scrobbler(String username, String encryptedPassword) { 
    6262        this.username = username; 
    63         this.password = password; 
     63        this.encryptedPassword = encryptedPassword; 
    6464        this.logger = Logger.getLogger(this.getClass().getPackage().getName()); 
    6565    } 
     
    152152 
    153153        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())); 
    157156 
    158157        String querystring = 
  • trunk/src/org/lastpod/UI.java

    r31 r32  
    4141    private JTextArea logtextarea; 
    4242    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    } 
    4351 
    4452    public void buildUI() {