2
0

Clear the password input field and pop a warning when entering bad master password.

This commit is contained in:
Maarten Billemont 2014-12-17 00:31:34 -05:00
parent 4c526d6f08
commit 1fbb6b0754
8 changed files with 49 additions and 24 deletions

View File

@ -46,4 +46,6 @@ public abstract class AuthenticationPanel extends JPanel {
public Iterable<? extends JButton> getButtons() { public Iterable<? extends JButton> getButtons() {
return ImmutableList.of(); return ImmutableList.of();
} }
public abstract void reset();
} }

View File

@ -21,6 +21,7 @@ import com.google.common.base.Charsets;
import com.google.common.io.*; import com.google.common.io.*;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
import com.lyndir.lhunath.opal.system.util.TypeUtils; import com.lyndir.lhunath.opal.system.util.TypeUtils;
import com.lyndir.masterpassword.MasterKey;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -103,12 +104,16 @@ public class GUI implements UnlockFrame.SignInCallback {
public boolean signedIn(final User user) { public boolean signedIn(final User user) {
if (!user.hasKey()) if (!user.hasKey())
return false; return false;
try {
user.getKey(); user.getKey();
passwordFrame = newPasswordFrame( user ); passwordFrame = newPasswordFrame( user );
open(); open();
return true; return true;
} catch (MasterKeyException e) {
JOptionPane.showMessageDialog( null, e.getLocalizedMessage(), "Sign In Failed", JOptionPane.ERROR_MESSAGE );
return false;
}
} }
protected PasswordFrame newPasswordFrame(final User user) { protected PasswordFrame newPasswordFrame(final User user) {

View File

@ -64,6 +64,11 @@ public class IncognitoAuthenticationPanel extends AuthenticationPanel implements
return fullNameField; return fullNameField;
} }
@Override
public void reset() {
masterPasswordField.setText( "" );
}
@Override @Override
protected User getSelectedUser() { protected User getSelectedUser() {
return new IncognitoUser( fullNameField.getText(), new String( masterPasswordField.getPassword() ) ); return new IncognitoUser( fullNameField.getText(), new String( masterPasswordField.getPassword() ) );

View File

@ -0,0 +1,11 @@
package com.lyndir.masterpassword.gui;
/**
* @author lhunath, 14-12-17
*/
public class MasterKeyException extends Exception {
public MasterKeyException(final String message) {
super( message );
}
}

View File

@ -144,6 +144,11 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite
} ); } );
} }
@Override
public void reset() {
masterPasswordField.setText( "" );
}
private ModelUser[] readConfigUsers() { private ModelUser[] readConfigUsers() {
return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function<MPUser, ModelUser>() { return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function<MPUser, ModelUser>() {
@Nullable @Nullable

View File

@ -52,13 +52,13 @@ public class ModelUser extends User {
@NotNull @NotNull
@Override @Override
public MasterKey getKey() { public MasterKey getKey() throws MasterKeyException {
MasterKey key = super.getKey(); MasterKey key = super.getKey();
if (!model.hasKeyID()) { if (!model.hasKeyID()) {
model.setKeyID( key.getKeyID() ); model.setKeyID( key.getKeyID() );
MPUserFileManager.get().save(); MPUserFileManager.get().save();
} else if (!model.hasKeyID( key.getKeyID() )) } else if (!model.hasKeyID( key.getKeyID() ))
throw new IllegalStateException( strf( "Incorrect master password for user: %s", getFullName() ) ); throw new MasterKeyException( strf( "Incorrect master password for user: %s", getFullName() ) );
return key; return key;
} }

View File

@ -18,6 +18,7 @@ public class UnlockFrame extends JFrame {
private final JPanel root; private final JPanel root;
private final JButton signInButton; private final JButton signInButton;
private final JPanel authenticationContainer; private final JPanel authenticationContainer;
private AuthenticationPanel authenticationPanel;
private boolean incognito; private boolean incognito;
public User user; public User user;
@ -64,7 +65,6 @@ public class UnlockFrame extends JFrame {
private void createAuthenticationPanel() { private void createAuthenticationPanel() {
authenticationContainer.removeAll(); authenticationContainer.removeAll();
final AuthenticationPanel authenticationPanel;
if (incognito) { if (incognito) {
authenticationPanel = new IncognitoAuthenticationPanel( this ); authenticationPanel = new IncognitoAuthenticationPanel( this );
} else { } else {
@ -125,13 +125,11 @@ public class UnlockFrame extends JFrame {
} }
void trySignIn(final JComponent... signInComponents) { void trySignIn(final JComponent... signInComponents) {
if (!checkSignIn()) { if (!checkSignIn())
return; return;
}
for (JComponent signInComponent : signInComponents) { for (JComponent signInComponent : signInComponents)
signInComponent.setEnabled( false ); signInComponent.setEnabled( false );
}
signInButton.setEnabled( false ); signInButton.setEnabled( false );
signInButton.setText( "Signing In..." ); signInButton.setText( "Signing In..." );
@ -149,10 +147,10 @@ public class UnlockFrame extends JFrame {
return; return;
} }
authenticationPanel.reset();
signInButton.setText( "Sign In" ); signInButton.setText( "Sign In" );
for (JComponent signInComponent : signInComponents) { for (JComponent signInComponent : signInComponents)
signInComponent.setEnabled( true ); signInComponent.setEnabled( true );
}
checkSignIn(); checkSignIn();
} }
} ); } );

View File

@ -3,8 +3,8 @@ package com.lyndir.masterpassword.gui;
import static com.lyndir.lhunath.opal.system.util.StringUtils.*; import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
import com.lyndir.masterpassword.MasterKey; import com.lyndir.masterpassword.MasterKey;
import java.security.KeyException;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
/** /**
@ -27,12 +27,11 @@ public abstract class User {
return key != null || (masterPassword != null && !masterPassword.isEmpty()); return key != null || (masterPassword != null && !masterPassword.isEmpty());
} }
@NotNull
@Nonnull @Nonnull
public MasterKey getKey() { public MasterKey getKey() throws MasterKeyException {
if (key == null) { if (key == null) {
if (!hasKey()) if (!hasKey())
throw new IllegalStateException( strf( "Master password unknown for user: %s", getFullName() ) ); throw new MasterKeyException( strf( "Master password unknown for user: %s", getFullName() ) );
key = new MasterKey( getFullName(), getMasterPassword() ); key = new MasterKey( getFullName(), getMasterPassword() );
} }