KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > passwdchanger > PasswdChanger


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.passwdchanger;
20
21 import org.lucane.client.*;
22 import org.lucane.client.widgets.*;
23 import org.lucane.common.*;
24 import org.lucane.common.crypto.MD5;
25 import org.lucane.common.net.ObjectConnection;
26 import java.awt.*;
27 import java.awt.event.*;
28 import javax.swing.*;
29
30
31 public class PasswdChanger extends StandalonePlugin
32 implements ActionListener
33 {
34     /* dialog components */
35     private ManagedWindow window;
36     private JTextField txtold;
37     private JTextField txtnew1;
38     private JTextField txtnew2;
39     private JButton btnChange;
40     
41     /* network and stream stuff */
42     private ConnectInfo cinfo;
43     
44     /**
45      * Void contructor. Used by PluginManager
46      */

47     public PasswdChanger()
48     {
49     }
50     
51     /**
52      * @param friends the Client the Plugin belongs to
53      * @param starter is true if the Clients started the plugin (start() will be
54      * called instead of follow()
55      * @return a new instance of the Plugin.
56      */

57     public Plugin newInstance(ConnectInfo[] friends)
58     {
59         return new PasswdChanger();
60     }
61     
62     /**
63      * Show a dialog asking for the friend name
64      */

65     public void start()
66     {
67         this.cinfo = Communicator.getInstance().getConnectInfo("org.lucane.applications.passwdchanger");
68         window = new ManagedWindow(this, getTitle());
69         window.setExitPluginOnClose(true);
70         window.getContentPane().setLayout(new GridLayout(0, 2));
71         txtold = new JPasswordField();
72         txtnew1 = new JPasswordField();
73         txtnew2 = new JPasswordField();
74         btnChange = new JButton(tr("button"));
75         btnChange.addActionListener(this);
76         window.getContentPane().add(new JLabel(tr("old")));
77         window.getContentPane().add(txtold);
78         window.getContentPane().add(new JLabel(tr("new")));
79         window.getContentPane().add(txtnew1);
80         window.getContentPane().add(new JLabel(tr("check")));
81         window.getContentPane().add(txtnew2);
82         window.getContentPane().add(new JLabel(""));
83         window.getContentPane().add(btnChange);
84         window.show();
85     }
86     
87     /**
88      * Do something on a buttonclick. If it is the dialog button, initailize
89      * everything. If it is the main button, send the message.
90      *
91      * @param ae the ActionEvent
92      */

93     public void actionPerformed(ActionEvent ae)
94     {
95         if(txtnew1.getText().length() == 0)
96         {
97             DialogBox.info(tr("nullpasswd"));
98             return;
99         }
100         
101         if(! txtnew1.getText().equals(txtnew2.getText()))
102         {
103             DialogBox.error(tr("typo"));
104             return;
105         }
106         
107         try
108         {
109             ObjectConnection oc = Communicator.getInstance().sendMessageTo(cinfo,
110                     "org.lucane.applications.passwdchanger", "CHANGE_PASSWD " +
111                     MD5.encode(txtold.getText()) + " " +
112                     MD5.encode(txtnew1.getText()));
113             String JavaDoc response = oc.readString();
114             oc.close();
115             
116             if(response.equals("BAD_PASSWD"))
117                 DialogBox.error(tr("invalid"));
118             else if(response.equals("PASSWD_CHANGED"))
119             {
120                 DialogBox.info(tr("modified"));
121                 window.dispose();
122                 exit();
123             }
124         }
125         catch(Exception JavaDoc e)
126         {
127             DialogBox.error(tr("error") + e);
128         }
129     }
130 }
131
Popular Tags