The following C# code will generate a random number without repeating character
public static string GetRandomPassword(int passwordLength)
{
string allowedChars = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?~ABCDEFGHIJKLMNOPQRSTUVWXYZ^&";
string newPassword = "";
Random randomNumber = new Random();
for (int i = 0; i <>
{
int charIndex = randomNumber.Next(allowedChars.Length);
//Don't Allow Repetation of Characters
if (!newPassword.Contains(allowedChars[charIndex] + ""))
newPassword += allowedChars[charIndex];
else
i--;
}
return newPassword;
No comments:
Post a Comment