com.sshtools.ui.swing
Class PasswordPairList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by com.sshtools.ui.swing.PasswordPairList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class PasswordPairList
extends java.util.ArrayList

A password together with a key (PasswordKey) that makes it unique makes up a PasswordPair. This object holds a list of these pairs and also is responsible for saving the list to disk, possibly encrypted if an Encrypter instance has been registered.

Author:
magicthize
See Also:
Serialized Form

Field Summary
protected static java.lang.String ENC
           
protected static java.lang.String ENCRYPTED_FORMAT
           
protected static java.lang.String FORMAT_KEY
           
protected static java.lang.String PLAIN_FORMAT
           
protected static PasswordKey PWMGR
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
PasswordPairList(java.io.File passwordFile)
          Creates a new PasswordPairList object.
 
Method Summary
 void addKey(PasswordKey key, java.lang.String userPassword, boolean persistant, boolean encrypted)
          Add a new password key with a new password.
 void addPair(PasswordPair pair)
          Add a new password pair to the list.
 void changeMasterPassword(char[] newMasterPassword, char[] oldMasterPassword)
          Change the master password and rewrite the password list.
 boolean checkMasterPassword(char[] p)
          Test if the password file can be decrypted given the master password.
 char[] getMasterPassword()
          Get the master password
 PasswordPair getPair(PasswordKey key)
          Get a password pair given its key.
 java.io.File getPasswordFile()
          Return the password list file
 PasswordPair getPasswordPairAt(int r)
          Get a PasswordPair at a given index in the list
 boolean isLoaded()
          Get if the list is loaded.
 void loadPasswordFile()
          Load the password list from disk.
 void newPasswordFile(char[] password)
          New password list.
 void removeKey(PasswordKey key)
          Remove a password pair from the list given its key.
 void reset()
           
 void savePasswordFile()
          Save all of the passwords to disk.
 void setKey(PasswordKey key, java.lang.String userPassword, boolean persistant, boolean encrypted)
          Set the supplied PasswordPair and update the password.
 void setMasterPassword(char[] masterPassword)
          Set the master password.
 void setPair(PasswordPair pair)
          Set the supplied PasswordPair.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

ENC

protected static final java.lang.String ENC
See Also:
Constant Field Values

FORMAT_KEY

protected static final java.lang.String FORMAT_KEY
See Also:
Constant Field Values

ENCRYPTED_FORMAT

protected static final java.lang.String ENCRYPTED_FORMAT
See Also:
Constant Field Values

PLAIN_FORMAT

protected static final java.lang.String PLAIN_FORMAT
See Also:
Constant Field Values

PWMGR

protected static final PasswordKey PWMGR
Constructor Detail

PasswordPairList

public PasswordPairList(java.io.File passwordFile)
                 throws java.io.IOException
Creates a new PasswordPairList object.

Parameters:
passwordFile - file to store passwords in
Throws:
java.io.IOException
Method Detail

checkMasterPassword

public boolean checkMasterPassword(char[] p)
Test if the password file can be decrypted given the master password.

Parameters:
p - master password
Returns:
valid password
Throws:
java.io.IOException - if password file cannot be read

changeMasterPassword

public void changeMasterPassword(char[] newMasterPassword,
                                 char[] oldMasterPassword)
                          throws java.lang.Exception
Change the master password and rewrite the password list.

Parameters:
newMasterPassword - new master password
Throws:
java.io.IOException - if the password file cannot be written
java.lang.Exception

setPair

public void setPair(PasswordPair pair)
Set the supplied PasswordPair. If the pairs key already exists it will be overwritten, if not it will be created. The list will not be saved.

Parameters:
pair - password pair

setKey

public void setKey(PasswordKey key,
                   java.lang.String userPassword,
                   boolean persistant,
                   boolean encrypted)
Set the supplied PasswordPair and update the password. If the pairs key already exists it will be overwritten, if not it will be created. The list will not be saved.

Parameters:
key - key
userPassword - new password

addKey

public void addKey(PasswordKey key,
                   java.lang.String userPassword,
                   boolean persistant,
                   boolean encrypted)
Add a new password key with a new password. A PasswordPair will be created and added to the list.

Parameters:
key - key
userPassword - key
persistant - persistant
encrypted - encrypted

addPair

public void addPair(PasswordPair pair)
Add a new password pair to the list. The list will not be saved.

Parameters:
pair - pair

getPasswordPairAt

public PasswordPair getPasswordPairAt(int r)
Get a PasswordPair at a given index in the list

Parameters:
r - index in list
Returns:
password pair

removeKey

public void removeKey(PasswordKey key)
Remove a password pair from the list given its key. The list will not be saved.

Parameters:
key - key to remove

getPair

public PasswordPair getPair(PasswordKey key)
Get a password pair given its key. null will be returned if no password with the supplied key can be found

Parameters:
key - key
Returns:
password pair

getMasterPassword

public char[] getMasterPassword()
Get the master password

Returns:
master password

setMasterPassword

public void setMasterPassword(char[] masterPassword)
Set the master password.

Parameters:
masterPassword - master password

savePasswordFile

public void savePasswordFile()
                      throws java.lang.Exception
Save all of the passwords to disk.

Throws:
java.io.IOException - if the password file cannot be written
java.lang.Exception

isLoaded

public boolean isLoaded()
Get if the list is loaded. It will not have been loaded if never used before (the password file doesn't exist)


newPasswordFile

public void newPasswordFile(char[] password)
                     throws java.lang.Exception
New password list.

Parameters:
password -
Throws:
java.lang.Exception - if password file cannot be read

loadPasswordFile

public void loadPasswordFile()
                      throws java.io.IOException
Load the password list from disk.

Throws:
java.io.IOException - if password file cannot be read

getPasswordFile

public java.io.File getPasswordFile()
Return the password list file

Returns:
password list file

reset

public void reset()


Copyright © 2003-2009 SSHTOOLS LTD. All Rights Reserved.