1
Ideally you should create GUID if you want unique strings, but GUID is very big for a username or password. You can also try to generate random alphanumeric text as username/password but you have to make sure that you check that this does not exists for any existing user before you send the email. Here is an example:
you can use the useLetter parameter to generate username in alphabets and password in numbers or change the code to use both.
public static string GenerateString(int length, bool useLetter)
{
string charsandspecialonly = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
string numberonly = "1234567890";
char[] chars = new char[length];
Random rd = new Random();
for (int i = 0; i < length; i++)
{
if (useLetter)
{
chars[i] = charsandspecialonly[rd.Next(0, charsandspecialonly.Length)];
}
else
{
chars[i] = numberonly[rd.Next(0, numberonly.Length)];
}
}
return new string(chars);
}