You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
5.3 KiB
185 lines
5.3 KiB
package de.memtext.dlg; |
|
|
|
import java.awt.Dimension; |
|
import java.awt.Font; |
|
import java.awt.Frame; |
|
import java.awt.GridLayout; |
|
import java.awt.event.KeyEvent; |
|
|
|
import javax.swing.JLabel; |
|
import javax.swing.JPanel; |
|
import javax.swing.JPasswordField; |
|
import javax.swing.JTextField; |
|
import javax.swing.KeyStroke; |
|
|
|
import de.memtext.rights.NewPasswordChecker; |
|
import de.memtext.util.WindowUtils; |
|
import de.memtext.widgets.HorizontalBox; |
|
import de.memtext.widgets.WarningMessage; |
|
|
|
public abstract class PasswdChangeDlg extends OkCancelDlg { |
|
private JLabel lblInfoDummy=new JLabel(); |
|
private NewPasswordChecker newPasswordChecker; |
|
private boolean isCheckOldPasswdWanted = true,isNewPasswordRequired=true; |
|
private JTextField usernameField = new JTextField(20); |
|
private KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
|
private JLabel lblInfo=new JLabel(); |
|
private JLabel lbl0 = new JLabel("Username:", JLabel.RIGHT); |
|
private JLabel lbl1 = new JLabel("altes Passwort:", JLabel.RIGHT); |
|
private JPasswordField oldpasswField = new JPasswordField(30); |
|
private JLabel lbl2 = new JLabel("neues Passwort:", JLabel.RIGHT); |
|
private JPasswordField newpasswField = new JPasswordField(30); |
|
private JLabel lbl3 = new JLabel("wiederholen:", JLabel.RIGHT); |
|
private JPasswordField newpasswField2 = new JPasswordField(30); |
|
|
|
public PasswdChangeDlg(Frame frame, String title) { |
|
super(frame, title, true); |
|
JPanel p=new JPanel(); |
|
p.add(lblInfo); |
|
HorizontalBox hbox = new HorizontalBox(); |
|
JPanel lblPanel = new JPanel(new GridLayout(0, 1)); |
|
lblPanel.setMaximumSize(new Dimension(150, 100)); |
|
|
|
|
|
lblPanel.add(lbl0); |
|
lblPanel.add(lbl1); |
|
lblPanel.add(lbl2); |
|
lblPanel.add(lbl3); |
|
|
|
lblInfo.setVisible(false); |
|
hbox.add(lblPanel); |
|
JPanel fieldPanel = new JPanel(new GridLayout(0, 1)); |
|
|
|
fieldPanel.add(usernameField); |
|
usernameField.getKeymap().removeKeyStrokeBinding(enter); |
|
|
|
fieldPanel.add(oldpasswField); |
|
oldpasswField.getKeymap().removeKeyStrokeBinding(enter); |
|
fieldPanel.add(newpasswField); |
|
newpasswField.getKeymap().removeKeyStrokeBinding(enter); |
|
fieldPanel.add(newpasswField2); |
|
newpasswField2.getKeymap().removeKeyStrokeBinding(enter); |
|
hbox.add(fieldPanel); |
|
this.setCenter(hbox); |
|
this.setNorth(p); |
|
this.pack(); |
|
WindowUtils.center(this); |
|
} |
|
public void setNewPasswordChecker(NewPasswordChecker newPasswordChecker) |
|
{ |
|
this.newPasswordChecker=newPasswordChecker; |
|
} |
|
public void setUsername(String username) { |
|
usernameField.setText(username); |
|
} |
|
public void clear() { |
|
usernameField.setText(""); |
|
oldpasswField.setText(""); |
|
newpasswField.setText(""); |
|
newpasswField2.setText(""); |
|
} |
|
protected abstract boolean isOldPasswordOK(String username, String passwd); |
|
|
|
/** |
|
* wenn OK geklickt wird wird automatisch geprüft ob die Länge des neuen |
|
* Passwort passt und beide gleich sind |
|
*/ |
|
protected final void performOk() { |
|
String new1 = new String(newpasswField.getPassword()); |
|
if (new1==null||new1.length()<4 ) |
|
{ |
|
WarningMessage.show(this, |
|
"Das neue Passwort ist zu kurz.", |
|
"Achtung"); |
|
return; |
|
} |
|
|
|
String new2 = new String(newpasswField2.getPassword()); |
|
String oldPassword = new String(oldpasswField.getPassword()); |
|
if (!new1.equals(new2)) { |
|
WarningMessage.show(this, |
|
"Die beiden neuen Passwörter stimmen nicht überein", |
|
"Achtung"); |
|
return; |
|
} |
|
String faults=null; |
|
if (newPasswordChecker!=null) faults=newPasswordChecker.checkForFaults(getUsername(),new String(newpasswField.getPassword())); |
|
|
|
if (faults!=null) { |
|
WarningMessage.show(this, |
|
faults, |
|
"Achtung"); |
|
return; |
|
} |
|
|
|
if (isNewPasswordRequired&&new1.equals(oldPassword)) |
|
{ |
|
WarningMessage.show(this,"Sie müssen ein neues Passwort eingeben","Achtung"); |
|
return; |
|
} |
|
|
|
if (isCheckOldPasswdWanted |
|
&& !isOldPasswordOK(usernameField.getText(), |
|
oldPassword)) { |
|
WarningMessage.show(this,"Das alte Passwort stimmt nicht", "Achtung"); |
|
return; |
|
} |
|
this.hide(); |
|
} |
|
|
|
protected void performCancel() { |
|
this.hide(); |
|
} |
|
|
|
|
|
public void setUsernameFieldEnabled(boolean b) { |
|
usernameField.setEnabled(b); |
|
} |
|
public void setOldPassword(String passw) { |
|
oldpasswField.setText(passw); |
|
} |
|
public String getUsername() { |
|
return usernameField.getText(); |
|
} |
|
public String getOldPasswd() { |
|
return new String(oldpasswField.getPassword()); |
|
} |
|
public String getNewPasswd() { |
|
return new String(newpasswField.getPassword()); |
|
} |
|
public boolean isCheckOldPasswdWanted() { |
|
return isCheckOldPasswdWanted; |
|
} |
|
|
|
public void setCheckOldPasswdWanted(boolean b) { |
|
isCheckOldPasswdWanted = b; |
|
lbl1.setVisible(b); |
|
oldpasswField.setVisible(b); |
|
} |
|
public void setInfoLabel(String txt) { |
|
lblInfo.setVisible(true); |
|
lblInfo.setText(txt); |
|
lblInfo.setFont(new Font("SansSerif",Font.BOLD,12)); |
|
} |
|
|
|
public boolean isNewPasswordRequired() { |
|
return isNewPasswordRequired; |
|
} |
|
|
|
public void setNewPasswordRequired(boolean b) { |
|
isNewPasswordRequired = b; |
|
} |
|
public static void main(String a[]) |
|
{ |
|
PasswdChangeDlg dlg=new PasswdChangeDlg(null,"dummy"){ |
|
|
|
protected boolean isOldPasswordOK(String username, String passwd) { |
|
return false; |
|
}} |
|
; |
|
dlg.setInfoLabel("bitte ändern"); |
|
dlg.show(); |
|
} |
|
} |
|
|
|
//Created on 09.01.2004 at 17:16:16
|