Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

You can use the following c# function to generate a random password containing only alphanumeric characters [a-z], [A-Z], [1-9].

private string GenerateAlphanumericPassword(int length)
{
    System.Text.StringBuilder builder = new System.Text.StringBuilder();
    Random r = new Random();
                    
    int[,] range = 
                { 
                   { 49, 58 },      // 1 - 9 (not 0)
                   { 65, 79 },      // A - N (not O)
                   { 97, 111 },     // a - n (not o)
                   { 49, 58 },      // 1 - 9 (not 0)
                   { 80, 91 },      // P - Z
                   { 112, 123 }     // p - z
                };

    int count = 0;
    while (count < length)
    {              
        int randomNum = r.Next(0, 5);

        builder.Append( (char)r.Next(range[randomNum, 0], range[randomNum, 1]) );

        count++;
    }            

    return builder.ToString();
}

 © Evident Interactive BV