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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started