1 /*
2  * Helper class for simple Server authentication applet
3  */
4 
5 import netscape.javascript.*;
6 import java.awt.*;
7 public class Auth extends java.applet.Applet {
8 
9 public TextField password;
init()10 public void init() {
11 	GridBagLayout grid = new GridBagLayout();
12 	int rowHeights[] = {0};
13 	int columnWidths[] = {0};
14 	double rowWeights[] = {0.0};
15 	double columnWeights[] = {0.0};
16 	grid.rowHeights = rowHeights;
17 	grid.columnWidths = columnWidths;
18 	grid.rowWeights = rowWeights;
19 	grid.columnWeights = columnWeights;
20 
21 	password = new TextField(8);
22 	password.setEchoCharacter('*');
23 	this.add(password);
24 
25 	GridBagConstraints con = new GridBagConstraints();
26 	con.gridx = 0;
27 	con.gridy = 0;
28 	con.anchor = GridBagConstraints.CENTER;
29 	con.fill = GridBagConstraints.HORIZONTAL;
30 	grid.setConstraints(password, con);
31 	setLayout(grid);
32 }
33 
34 /* compute the MD5 digest of the input string with the password on the front */
35 
digest(String value)36 public String digest(String value) {
37     System.out.println(value + " + " + password.getText());
38     MD5 digest = new MD5();
39     digest.init();
40     digest.updateASCII(password.getText());
41     digest.updateASCII(value);
42     digest.finish();
43     System.out.println(digest.toString());
44     return digest.toString();
45 }
46 
47 /* eval an arbitrary javascript command, return a string value */
48 /* just testing now */
49 
js(String script)50 public String js(String script) {
51     JSObject win;
52     win = JSObject.getWindow(this);
53     String result = (String)win.eval(script);
54     /* JSObject.alert(result); */
55     return result;
56 }
57 }
58