Java Reference
In-Depth Information
1 /*
2
Chapter 11: The Password Class
3
Programmer: Michael Mick
4
Date:
December 12, 2007
5
Filename:
Password.java
6
Purpose:
To provide a reusable Password class which uses PasswordException
7 */
8
9 import java.util.*;
10 import java.io.*;
11
12 public class Password implements Serializable
13 {
14
final static int MIN_SIZE = 6;
15
final static int MAX_SIZE = 15;
16
static int maxHistory = 4;
17
static int expiresNotifyLimit = 3;
18
19
private int maxUses = 120;
20
private int remainingUses = maxUses;
21
private boolean autoExpires = true ;
22
private boolean expired = false ;
23
24
private ArrayList pswdHistory;
25
26
27
// Constructors for objects of class Password
28
public Password ( String newPassword ) throws PasswordException
29
{
30
pswdHistory = new ArrayList ( maxHistory ) ;
31
set ( newPassword ) ;
32
}
FIGURE 11-4
In addition to Password, other classes from the previous chapter also are
needed, as mentioned earlier. The following steps obtain the needed files and
then open the existing Password source code file in TextPad.
To Open an Existing Java Program in TextPad
1. Insert the Data Disk in drive A.
2. Copy the files listed in Table 11-3 from the location where you saved or
compiled them in the previous chapter (the Chapter10 folder or the
location specified by your instructor) to the Chapter11 folder on your
Data Disk or a location specified by your instructor.
3. Start TextPad. If necessary, click Line Numbers on the View menu to
display line numbers.
4. Open the file, Password.java, from the Chapter11 folder or the location
specified by your instructor.
The file, Password.java, on the Data Disk in drive A is opened in TextPad
(Figure 11-5).
Search WWH ::




Custom Search