Monday, August 6, 2012

Generate Random String c#

private string GeneratePassword()
    {

        Random rng = new Random();
        string _chars =  
                         "ABCDEFGHIJKLMNOPQRSTUVWXYZqwertyuiopplkjhgfdsazxcvbnm1234567890";
        int size = rng.Next(8,12);

        char[] buffer = new char[size];

        for (int i = 0; i < size; i++)
        {
            buffer[i] = _chars[rng.Next(_chars.Length)];
        }
        return new string(buffer);
    }

No comments:

Post a Comment