Question: Java: please explain this code. Is there a better way to code these two methods? Thanks. /** * Method to make sure the password meets

Java: please explain this code. Is there a better way to code these two methods? Thanks.

/** * Method to make sure the password meets the requirements of one special character, one number and 8 characters * long or more. */ private boolean passwordCheck() { int asciiValueClearPswd[] = new int [100]; int asciiValueClearPswdTwo[] = new int [100]; for(int i = 0; i < clearPassword.length(); i++) { asciiValueClearPswd[i] = clearPassword.charAt(i); for(int j = 0; j < clearPassword.length(); j++) { asciiValueClearPswdTwo[j] = clearPassword.charAt(j); if((asciiValueClearPswd[i] >= 35 && asciiValueClearPswd[i] <= 38) && (asciiValueClearPswdTwo[j] >= 48 && asciiValueClearPswdTwo[j] <= 57) && (clearPassword.length() > 7)) { return true; } }

} return false; }

/** * The method that encrypts the clear password. Uses Vigenere Cipher for Ascii characters */ private void encrypt() {

int j = 0; int encryptNum[] = new int[100]; int asciiValueKey[] = new int[100]; int asciiValueClearPswd[] = new int [100]; byte encryptByte [] = new byte [clearPassword.length()]; for(int i = 0; i < clearPassword.length(); i++) { asciiValueKey[i] = key.charAt(j); asciiValueClearPswd[i] = clearPassword.charAt(i); encryptNum[i] = asciiValueKey[i] - 33; encryptNum[i] = (encryptNum[i] + asciiValueClearPswd[i]) - 90; encryptByte[i] = (byte) encryptNum[i];

if(encryptNum[i] < 33) { encryptNum[i] = (encryptNum[i] - 32) + 122; encryptByte[i] = (byte) encryptNum[i]; } if(key.length() - j == 1) { j = 0; } else { j++; } encryptedPassword = new String(encryptByte); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!