Java Reference
In-Depth Information
PROBLEM ANALYSIS The problem that the Password class should solve is
to encapsulate consistent password functionality that will be used by other pro-
grams, rather than to be an independent program. The requirements document
shown in Figure 9-2 outlines several attributes and behaviors for the Password
class. The Password class is to encrypt all passwords according to the algorithm
presented in the requirements document.
The Password class also will contain several values that apply to all
passwords, such as a minimum password size (6 characters), a maximum
password size (15 characters), the maximum number of entries in the password
history (4), and a usage expiration notification limit (3) that, when reached, trig-
gers a notification to the user that the current password is expiring. The values
of these items are the same for all Password objects. The Password class also
contains some values that vary for each Password object, such as the maximum
number of uses, the remaining number of uses, whether the password is set to
expire automatically, if it has expired, and the history of passwords used.
The Password class will accumulate a history, or collection, of recently used
passwords, including the current password; verify the format of all passwords to
ensure that they are between the minimum and maximum length and that they
contain at least one numeric character; validate a given password against the
current password value; determine if the current password is approaching
expiration; provide the number of remaining uses to a user; provide whether
the password is set to expire automatically for a user; and allow the automatic
expiration to be activated or inactivated.
DESIGN THE SOLUTION Once you
have analyzed the problem and under-
stand the needs, the next step is to
design the class. Figure 9-3 shows an
example of a class diagram for the
Password class, with the attributes and
methods determined from the analysis
of the requirements document. The
top four attributes apply equally to all
instances of the class, while the next
five may have unique values for each
object. Of the 15 methods listed, the
last two are needed only within the
class, while the remaining 13 methods
are available to all users. Constructor
methods are not listed, as a general
need for constructors is assumed, and
because constructors differ only in
their parameter lists, which are not
shown here for any of the methods.
Table 9-2 summarizes the methods in
the Password class.
Password
MIN_SIZE
MAX_SIZE
maxHistory
expiresNotifyLimit
maxUses
remainingUses
autoExpires
expired
pswdHistory
getAutoExpires()
setAutoExpires()
isExpired()
setExpired()
getExpiresNotifyLimit()
setExpiresNotifyLimit()
getMaxHistory()
setMaxHistory()
getHistorySize
getRemaining Uses()
isExpiring
set()
validate()
verifyFormat()
encrypt()
FIGURE 9-3
Search WWH ::




Custom Search