Clear the password input field and pop a warning when entering bad master password.
This commit is contained in:
parent
4c526d6f08
commit
1fbb6b0754
@ -46,4 +46,6 @@ public abstract class AuthenticationPanel extends JPanel {
|
||||
public Iterable<? extends JButton> getButtons() {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public abstract void reset();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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() ) );
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
} );
|
||||
|
@ -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() );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user