Random String Generation in ASP.Net


/*  Random Password Using RNG  */
                //Method1 Using RNG Crypto Service Provider
                byte[] saltpass = new byte[4];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetBytes(saltpass);
                test = Convert.ToBase64String(saltpass);
                test = test.Remove(test.Length - 3, 3);//This is for removing last 3 chatcters from random string

                //Method2 using Get Random file name it will creates a file name with .tmp extension so replace with null after .(dot) and the default Length of file is 11 with out extension
                string outpass = Path.GetRandomFileName();
                outpass = outpass.Replace(".", ""); // Remove period.
                outpass = outpass.Remove(outpass.Length - 3, 3);


You Can Download the Working Code From here.