/src/mpv5/ui/dialogs/LoginScreen.java
Java | 231 lines | 180 code | 31 blank | 20 comment | 8 complexity | 12d086df92669cf9dc717e954dd6c950 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
- /*
- * login.java
- *
- * Created on 7. August 2008, 21:47
- */
- package mpv5.ui.dialogs;
- import java.awt.Component;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.security.NoSuchAlgorithmException;
- import mpv5.Main;
- import mpv5.db.common.NodataFoundException;
- import mpv5.globals.LocalSettings;
- import mpv5.globals.Messages;
- import mpv5.logging.Log;
- import mpv5.ui.frames.MPView;
- import mpv5.ui.misc.Position;
- import mpv5.db.objects.User;
- import mpv5.usermanagement.Lock;
- import mpv5.utils.text.MD5HashGenerator;
- /**
- *
- *
- */
- public class LoginScreen extends javax.swing.JFrame {
- /** Creates new form login
- * @param toUnlock
- */
- public LoginScreen(Component toUnlock) {
- initComponents();
- if (!LocalSettings.getProperty("lastuser").equals("null")) {
- jCheckBox1.setSelected(true);
- try {
- jTextField1.setText(new User(Integer.valueOf(LocalSettings.getProperty("lastuser"))).getName());
- } catch (NodataFoundException ex) {
- Log.Debug(this, ex);
- }
- jPasswordField1.requestFocus();
- }
- this.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent e) {
- close();
- }
- private void close() {
- LocalSettings.setProperty(LocalSettings.LAST_USER, null);
- LocalSettings.setProperty(LocalSettings.LAST_USER_PW, null);
- LocalSettings.save();
- Main.getApplication().exit();
- }
- });
- new Position(this);
- this.setVisible(rootPaneCheckingEnabled);
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jButton1 = new javax.swing.JButton();
- jPasswordField1 = new javax.swing.JPasswordField();
- jLabel3 = new javax.swing.JLabel();
- jCheckBox1 = new javax.swing.JCheckBox();
- jCheckBox2 = new javax.swing.JCheckBox();
- jLabel4 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
- java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
- setTitle(bundle.getString("LoginScreen.title")); // NOI18N
- setAlwaysOnTop(true);
- setFocusTraversalPolicyProvider(true);
- setResizable(false);
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("LoginScreen.jPanel1.border.title"))); // NOI18N
- jLabel1.setText(bundle.getString("LoginScreen.jLabel1.text")); // NOI18N
- jLabel2.setText(bundle.getString("LoginScreen.jLabel2.text")); // NOI18N
- jButton1.setText(bundle.getString("LoginScreen.jButton1.text")); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jPasswordField1.setToolTipText(bundle.getString("LoginScreen.jPasswordField1.toolTipText")); // NOI18N
- jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jPasswordField1ActionPerformed(evt);
- }
- });
- jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/lock.png"))); // NOI18N
- jCheckBox1.setText(bundle.getString("LoginScreen.jCheckBox1.text")); // NOI18N
- jCheckBox2.setText(bundle.getString("LoginScreen.jCheckBox2.text")); // NOI18N
- jLabel4.setFont(new java.awt.Font("Tahoma", 2, 11));
- jLabel4.setText(bundle.getString("LoginScreen.jLabel4.text")); // NOI18N
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jCheckBox1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jCheckBox2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
- .addComponent(jButton1))
- .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
- .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jLabel2))
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jCheckBox2)))
- .addContainerGap(13, Short.MAX_VALUE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- login();
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed
- login();
- }//GEN-LAST:event_jPasswordField1ActionPerformed
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JCheckBox jCheckBox2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPasswordField jPasswordField1;
- private javax.swing.JTextField jTextField1;
- // End of variables declaration//GEN-END:variables
- private void login() {
- User user = mpv5.usermanagement.MPSecurityManager.checkAuth(jTextField1.getText(), new String(jPasswordField1.getPassword()));
- if (user != null) {
- user.login();
- Lock.unlock(mpv5.YabsViewProxy.instance().getIdentifierFrame());
- if (jCheckBox1.isSelected()) {
- LocalSettings.setProperty("lastuser", mpv5.db.objects.User.getCurrentUser().__getIDS().toString());
- } else {
- LocalSettings.setProperty("lastuser", "INSTANCE");
- }
- if (jCheckBox2.isSelected()) {
- try {
- LocalSettings.setProperty("lastuserpw", MD5HashGenerator.getInstance().hashData(jPasswordField1.getPassword()));
- } catch (NoSuchAlgorithmException ex) {
- Log.Debug(ex);
- }
- } else {
- LocalSettings.setProperty("lastuserpw", "ZFIFZIUG876KJIHJu888iouu");
- }
- LocalSettings.save();
- this.dispose();
- } else {
- jLabel4.setText(Messages.ACCESS_DENIED.getValue());
- }
- }
- }