Jump to content

Illegal Start Of Expression


yrstruly

Recommended Posts

HiCan somebody please tell me what i wrong witht he following code, i get an error message ?Illegal start of expression, line 67/*Chapter 9: The Password ClassProgrammer:Michael MickDate: November 25, 2004Filename: Password.javaPurpose: To provide a reusable Password class*/import java.util.*;public class Password{ final static int MIN_SIZE = 9; final static int MAX_SIZE = 15; static int maxHistory = 4; static int expiresNotifyLimit = 3; private int maxUses = 120; private int remainingUses = maxUses; private boolean autoExpires = true; private boolean expired = False; private ArrayList pswdHistory; // Construction for object class Password public Password(String newPassword) throws Exception { pswdHistory = new ArrayList(maxHistory); set(newPassword); } public Password(String newPassword, int numMaxUses) throws Exception { pswdHistory = new ArrayList(maxHistory); maxUses = numMaxUses; remainingUses = numMaxUses; set(newPassword); } public Password(String newPassword, boolean pswdAutoExpires) throws Exception { pswdHistory = new ArrayList(maxHistory); autoExpires = pswdAutoExpires; set(newPasword); } public Password(String newPassword, int numMaxUses, boolean pswdAutoExpires) throws Exception { pswdHistory = new ArrayList(maxHistory); maxUses = numMaxUses; remainingUses = numMaxUses; autoExpires = pswdAutoExpires; set(newPassword);} public boolean getAutoExpires() { return autoExpires; } public void setAutoExpires(boolean autoExpires) { this.autoExpires = autoExpires; if(autoExpires) remainingUses = maxUses; public boolean isExpired() { return expired; } public void setExpired(boolean newExpired) { expired = newExpired; } public int getExpiresNotifyLimit() { return expiresNotifyLimit; } public void setExpiresNotifyLimit(int newNotifyLimit) { if(newNotifyLimit >= 2 && newNotifyLimit <= 20) expiresNotifyLimit = newNotifyLimit; } public int getMaxHistory() { return maxHistory; } public void setMaxHistory(int newMaxHistory) { int overage = 0; if(newMaxHistory >= 1 && newMaxHistory <= 10) { maxHistory = newMaxHistory; overage = getHistorySize() - maxHistory; if(overage > 0) // if size > max allowed { do { pswdHistory.remove(0); // then remove overage number overage--; } while(overage > 0); // of oldest pswds from list pswdHistory.trimToSize(); // sesize capacity to max allowed } } } public int getRemainingUses() { return remainingUses; } public int getHistorySize() { return pswdHistory.size(); } public boolean isExpiring() { boolean expiring = false; if(autoExpires && remainingUses <= expiresNotifyLimit) expiring = true; return expiring; } // Set password to a new value; keeps current & previuos values in history up to max number public void set(String pswd) throws Exception { String encryptPswd; boolean pswdAdded = true; pswd = pswd.trim(); //remove any leading, trailing white space verifyFormat(pswd); // verify password was entered properly encryptPswd = encrypt(pswd); // convert to encrypted form if(!pswdHistory.contains(encryptPswd)) //if pswd not in recently used list { if(pswdHistory.size() == maxHistory) //if list is at max size pswdHistory.remove(0); //remove 1st, oldes, pswd from list pswdAdded = pswdHistory.add(encryptPswd); //add new pswd to end of ArrayList if(!pswdAdded) //should never happen throw new Exception("Internal list error - Password not accepted"); if(expired) //if pswd has expired, expired = false; //reset to not expired if(autoExpires) //if pswd auto expires, remainingUses = maxUses; //reset uses to max } else throw new Exception("Password recently used"); } // Validates entered passwod against most recently saved value public void validate(String pswd) throws Exception { String encryptedPswd; String currentPswd; int currentPswdIndex; verifyFormat(pswd); //verify password entered properly encryptPswd = encrypt(pswd); //convert to encrypte form if(!pswdHistory.isEmpty()) //at least one password entry is in history { currentPswdIndex = pswdHistory.size()-1; currentPswd = (String)pswdHistory.get(currentPswdIndex); if(!encryptPswd.equals(current)) // if not mot recent pswd throw new Exception("Password is invalid"); if(expired) throw new Exception("Pssword has expired - please change"); if(autoExpires) { --remainingUses; if(remainingUses <= 0) expired = true; } } else throw new Exception("No password on file - list corrupted!"); // should never hapen } // Verifies password has proper format private void verifyFormat(String pswd) throws Exception { boolean numFound = false; if(pswd.length() == 0) throw new Exception("No password provided!"); if(pswd.length() < MIN_SIZE) throw new Exception("Password must be at least "+MIN_SIZE+ "characters in lenght"); if(pswd.length() > MAX_SIZE) throw new Exception("Password cannot be greater than "+MAX_SIZE+ "characters in lenght"); // scan through password to find if at least 1 number is used for(int i=0; i < pswd.length() && !numFound; ++i) if(Character.isDigit(pswd.charAt(i))) numFound = true; if(!numFound) throw new Exception("Password is invalid - must have at least one numeric digit"); } // Encrypts original password returning new encrypted String private String encrypt(String pswd) { StringBuffer encryptPswd; int pswdSize = 0; int midpoint = 0; int hashCode = 0; // swap first and last half of password pswdSize = pswd.length(); midpoint = pswdSize/2; encryptedPswd = new StringBuffer(pswd.substring(midpoint) // get last half of pswd + pswd.substring(0,midpoint)); // and concatenate first half encryptedPswd.reverse(); // reverses orders of character in password for(int i=0; i < pswdSize; ++i) encryptedPswd.setCharAt(i, (char)(encryptPswd.charAt(i) & pswd.charAt(i)) ); hashCode = pswd.hasCode(); // hash code for original password encryptPswd.append(hashCode); return encryptPswd.toString(); } }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...