summaryrefslogtreecommitdiffstats
path: root/Bachelor/ERGO/TierheimVerw/thv/PwDialog.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/ERGO/TierheimVerw/thv/PwDialog.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/ERGO/TierheimVerw/thv/PwDialog.java')
-rw-r--r--Bachelor/ERGO/TierheimVerw/thv/PwDialog.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/Bachelor/ERGO/TierheimVerw/thv/PwDialog.java b/Bachelor/ERGO/TierheimVerw/thv/PwDialog.java
new file mode 100644
index 0000000..b5156dc
--- /dev/null
+++ b/Bachelor/ERGO/TierheimVerw/thv/PwDialog.java
@@ -0,0 +1,115 @@
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * @author Andreas Spirka, Sven Eisenhauer
+ * Benutzerauthentifizierungsdialog
+ */
+public class PwDialog extends AbstractMyJDlg {
+ Container c;
+ JPanel pTop = new JPanel();
+ JPanel pCenter = new JPanel();
+ JPanel pBottom = new JPanel();
+ JLabel l = new JLabel("login");
+ JLabel pw = new JLabel ("password");
+ JTextField tf = new JTextField(12);
+ JPasswordField pf = new JPasswordField(12);
+ JButton okB = new JButton("OK");
+ JButton abbrB = new JButton("Abbrechen");
+ User authUser = new User("gast","gast","Gast",1024,User.ROLE_GUEST);;
+ String fName = new String ("user.dat");
+
+ /**
+ * Konstruktor
+ * @param owner
+ * @param title
+ * @param modal
+ */
+ public PwDialog(Frame owner, String title, boolean modal) {
+ setSize(240,110);
+ this.setResizable(false);
+ setModal(modal);
+ c = getContentPane();
+ getRootPane().setDefaultButton(okB); //mit Eingabetaste bestätigen
+ c.setLayout( new GridLayout(3, 2,6,3 ) );
+ ButtonListener2 bl = new ButtonListener2(this);
+ okB.addActionListener(bl);
+ okB.setActionCommand("submitPW");
+ abbrB.addActionListener(bl);
+ abbrB.setActionCommand("abbrechen");
+ c.add(l);
+ c.add(tf);
+ c.add(pw);
+ c.add(pf);
+ c.add(okB);
+ c.add(abbrB);
+ setTitle(title);
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ Dimension frameSize = getSize();
+ setLocation((screenSize.width/2)-(frameSize.width/2),(screenSize.height/2)-(frameSize.height/2));
+ setVisible(true);
+ }
+
+ /* (non-Javadoc)
+ * @see AbstractMyJDlg#buttonActionPerformed(java.awt.event.ActionEvent)
+ */
+ public void buttonActionPerformed( ActionEvent e )
+ {
+ if (e.getActionCommand().equals("abbrechen"))
+ {
+ this.dispose();
+ }
+ if (e.getActionCommand().equals("submitPW"))
+ {
+ String name= new String(tf.getText());
+ String pw= new String(pf.getPassword());
+ UserCon userCon;
+ File myFile = new File(fName);
+ if(!myFile.exists())
+ {
+ userCon = new UserCon();
+ userCon.addUser(new User("adm","adm","Administrator",0,3));
+ try {
+ FileOutputStream fos = new FileOutputStream(fName);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(userCon);
+ oos.close();
+ fos.close();
+ } catch (Exception exception) { exception.printStackTrace(); }
+ }
+ try {
+ FileInputStream fis = new FileInputStream(fName);
+ ObjectInputStream ois = new ObjectInputStream(fis);
+ userCon = (UserCon) ois.readObject();
+ ois.close();
+ fis.close();
+ for (int i=0;i<userCon.size();i++)
+ {
+ String actname=new String(((User)userCon.elementAt(i)).getUserName());
+ String actpw=new String (((User)userCon.elementAt(i)).getPassWd());
+ if(name.equals(actname))
+ {
+ if(pw.equals(actpw))
+ {
+ //JOptionPane.showMessageDialog(this,"Benutzer "+name+" authentifiziert","Erfolg",JOptionPane.INFORMATION_MESSAGE);
+ setVisible(false);
+ authUser=(User)userCon.elementAt(i);
+ }//end if2
+ else
+ {
+ JOptionPane.showMessageDialog(this,"Benutzer "+name+" nicht authentifiziert","Misserfolg",JOptionPane.INFORMATION_MESSAGE);
+ }//end else
+ }//end if1
+ }//end for
+ } //end try
+ catch (Exception exception) { exception.printStackTrace(); }
+ }//end if0 get.source
+ }//buttonActionPerformed
+
+ /**
+ * @return User
+ */
+ public User getUser(){return authUser;};
+}//end class PwDialog