maskSensitiveValue function

String maskSensitiveValue(
  1. String value
)

Function to mask sensitive value while preserving some structure

Implementation

String maskSensitiveValue(String value) {
  if (value.isEmpty) return '';
  if (value.length <= 4) return '*' * value.length;

  // Preserve first and last character, mask the rest
  return '${value[0]}${'*' * (value.length - 2)}${value[value.length - 1]}';
}