    // Generate a random password with the specified length. The password will only  
   // contain digits and letters (either lowercase or uppercase)   
 public static string GetRandomPassword(int length)
  {  
      Random rand = new Random();  
      System.Text.StringBuilder password = new System.Text.StringBuilder(length);        
      for (int i = 1; i <= length; i++)
      { 
        int charIndex;        
        // allow only digits and letters 
        do
        {
          charIndex = rand.Next(48, 123);
        }while (!((charIndex >= 48 && charIndex <= 57) ||
         (charIndex >= 65 && charIndex <= 90) || (charIndex >= 97 && charIndex <= 122)));  
          // add the random char to the password being built 
         password.Append(Convert.ToChar(charIndex));         
      }
        return password.ToString();    
  }



