Refactored to use just one getCredential method
This commit is contained in:
parent
8e17fd2848
commit
ea057ec8d4
@ -4,17 +4,31 @@ import java.io.Console;
|
||||
import java.util.*;
|
||||
|
||||
public class credentialsProcessor {
|
||||
public static String getUsername(String thisPrompt) {
|
||||
Scanner myObj = new Scanner(System.in);
|
||||
System.out.print(thisPrompt);
|
||||
String varEntry;
|
||||
varEntry = myObj.nextLine();
|
||||
return varEntry;
|
||||
}
|
||||
public static String getCredential(String thisPrompt, int thisLength, boolean isSecret) {
|
||||
String thisReturn = null;
|
||||
if (isSecret)
|
||||
{
|
||||
Console console = System.console();
|
||||
char[] charValue = console.readPassword(thisPrompt);
|
||||
while (charValue != null && charValue.length < thisLength)
|
||||
{
|
||||
charValue = console.readPassword(thisPrompt);
|
||||
}
|
||||
thisReturn = String.copyValueOf(charValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Scanner myObj = new Scanner(System.in);
|
||||
System.out.print(thisPrompt);
|
||||
thisReturn = myObj.nextLine();
|
||||
while (thisReturn != null && thisReturn.toString().length() < thisLength)
|
||||
{
|
||||
System.out.print(thisPrompt);
|
||||
thisReturn = myObj.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
return thisReturn;
|
||||
|
||||
public static char[] getPassword(String thisPrompt) {
|
||||
Console console = System.console();
|
||||
char[] password = console.readPassword(thisPrompt);
|
||||
return password;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user