Search code examples
javaandroidrandomemail-verification

How to generate random code for Android application email verification


I am writing a new Android application that require the users to register and the system need to send emails to give them a code for email verification.

The random code need to be a 6-digit code that consisting numbers with uppercase alphabet, for example, 6H94BA. I have done some research and still cannot find anything. How to do that?


Solution

  • Try this:

    SecureRandom random = new SecureRandom();
    String randomCode = new BigInteger(30, random).toString(32).toUpperCase();