defaultVerificationCodeGenerator function

String defaultVerificationCodeGenerator({
  1. int length = 8,
})

Returns a secure random string to be used for short-lived verification codes.

The code is length digits long, 8 by default. Excludes the digit 0 to avoid confusion with the letter 'o'.

Implementation

String defaultVerificationCodeGenerator({int length = 8}) {
  const characters = '123456789';

  return String.fromCharCodes(
    Iterable.generate(
      length,
      (_) => characters.codeUnitAt(_random.nextInt(characters.length)),
    ),
  );
}