public abstract class Password {
private String password;
private final static String ENCRYPTION_METHOD;
static {
ENCRYPTION_METHOD = "CLEAR TEXT";
}
public Password(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public boolean matches (String aString) {
if (aString.equals(password)) {
return true; }
else {
return false; }
}
public String toString() {
return password;
}
public static String getEncryptionMethod() {
return ENCRYPTION_METHOD;
}
abstract String decrypt();
}
public class EncryptedPassword extends Password {
private final static String ENCRYPTION_METHOD;
static {
ENCRYPTION_METHOD = "PERMUTATION";
}
public EncryptedPassword(String password) {
super(password);
}
public boolean matches (String aString) {
if (aString.equals("True")) {
return true; }
else {
return false; }
}
public String toString() {
return "Password: " + super.toString();
}
public String setPassword() {
return getPassword();
}
public String decrypt() {
return getPassword();
}
public static String getEncryptionMethod() {
return ENCRYPTION_METHOD;
}
}
public class UserNamePassword extends EncryptedPassword {
private String userName;
public UserNamePassword(String password, String userName) {
super(password);
}
public String getUserName() {
return userName;
}
public boolean matches(String aString) {
return false;
}
public boolean matches(String userName, String password) {
if (userName.equals(password)) {
return true;
}
else {
return false; }
}
public String toString() {
return "User Name: " + userName + "Password: " + super.toString();
}
}
import csci130.*;
import java.lang.String.*;
public class Driver {
public static void main(String args[]){
System.out.println("Enter a user name: ");
String userName = KeyboardReader.readLine();
System.out.println("Enter a password: ");
String password = KeyboardReader.readLine();
Password pass = new EncryptedPassword("s0cci31");
System.out.println("Password reference pointing to an EncryptedPassword object");
System.out.println("-----------------------------------------------------------------------------");
System.out.println("Encrypted Password: " + pass.getPassword());
System.out.println(pass.getEncryptionMethod());
System.out.println(pass.toString());
System.out.println("Password is: " + password);
}
}
Overall I've allowed the user to input a user name and password
I want to Use the password to instantiate a new Password reference, which points to a EncryptedPassword object, but i'm not sure if i did that right.
I don't think i called the getPassword, getEncryptionMethod, and toString methods of the newly instantiated object, and printed the information to the screen correctly.
And i have no idea how to tell the user to re-enter the password and be able to tell them whether or not they entered it correctly... I could use some help, this has been very stressful..

New Topic/Question
This topic is locked



MultiQuote



|