diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java index 3dbca406..45d5133d 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java @@ -58,12 +58,19 @@ public class ModelUser extends User { if (!model.hasKeyID()) { model.setKeyID( key.getKeyID() ); MPUserFileManager.get().save(); - } else if (!model.hasKeyID( key.getKeyID() )) + } else if (!model.hasKeyID( key.getKeyID() )) { + reset(); throw new MasterKeyException( strf( "Incorrect master password for user: %s", getFullName() ) ); + } return key; } + @Override + public void reset() { + masterPassword = null; + } + @Override public Iterable findSitesByName(final String query) { return FluentIterable.from( model.findSitesByName( query ) ).transform( new Function() { diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java index 4c8573a1..4720ae1d 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java @@ -32,14 +32,22 @@ public abstract class User { @Nonnull public MasterKey getKey() throws MasterKeyException { if (key == null) { - if (!hasKey()) + String masterPassword = getMasterPassword(); + if (masterPassword == null || masterPassword.isEmpty()) { + reset(); throw new MasterKeyException( strf( "Master password unknown for user: %s", getFullName() ) ); - key = new MasterKey( getFullName(), getMasterPassword() ); + } + + key = new MasterKey( getFullName(), masterPassword ); } return key; } + public void reset() { + key = null; + } + public abstract Iterable findSitesByName(final String siteName); public abstract void addSite(final Site site);