obscureString method
Implementation
String obscureString(String input) {
int length = input.length;
// If the string is less than 5 characters, show only the first and last character
if (length < 3) {
if (length == 1) {
return input; // If the string is a single character, return it as is
}
return input[0] + '*' * (length - 2) + input[length - 1];
}
// For strings with 5 or more characters, show the first 3 and last 2 characters
return " ${input.substring(0, 3)}${'*' * (length - 5)}${input.substring(length - 2)}";
}