Tuesday 8 August 2017

Creating OTP

import java.util.*;

public class OTP
{
    static char[] OTP(int len)
    {
        System.out.println("Generating OTP : ");
        System.out.print("You OTP is : ");

        // Using numeric values
        String numbers = "0123456789";

        // Using random method
        Random rndm_method = new Random();

        char[] otp = new char[len];

        for (int i = 0; i < len; i++)
        {
           
            otp[i] = numbers.charAt(rndm_method.nextInt(numbers.length()));
        }
        return otp;
    }
    public static void main(String[] args)
    {
        int length = 4;
        System.out.println(OTP(length));
    }
}





OUTPUT:


Generating OTP :

You OTP is : 2438

No comments:

Post a Comment