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

View File

@ -64,6 +64,11 @@ public class IncognitoAuthenticationPanel extends AuthenticationPanel implements
return fullNameField;
}
@Override
public void reset() {
masterPasswordField.setText( "" );
}
@Override
protected User getSelectedUser() {
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() {
return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function<MPUser, ModelUser>() {
@Nullable

View File

@ -52,13 +52,13 @@ public class ModelUser extends User {
@NotNull
@Override
public MasterKey getKey() {
public MasterKey getKey() throws MasterKeyException {
MasterKey key = super.getKey();
if (!model.hasKeyID()) {
model.setKeyID( key.getKeyID() );
MPUserFileManager.get().save();
} 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;
}

View File

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

View File

@ -3,8 +3,8 @@ package com.lyndir.masterpassword.gui;
import static com.lyndir.lhunath.opal.system.util.StringUtils.*;
import com.lyndir.masterpassword.MasterKey;
import java.security.KeyException;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
/**
@ -27,12 +27,11 @@ public abstract class User {
return key != null || (masterPassword != null && !masterPassword.isEmpty());
}
@NotNull
@Nonnull
public MasterKey getKey() {
public MasterKey getKey() throws MasterKeyException {
if (key == null) {
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() );
}