I create a lot of code to C # with a random password to see. NET. But I feel the following code is very simple to create. Maybe I'm wrong, but I have my solution to this problem.
If you want a better way go through the given below code:
static string CreateRandPass(int numberOfChar)
{
if (numberOfChar <= 0 || numberOfChar > 32)
{
throw new ArgumentException(“A password of only length 1 to 32 can be generated.”);
}
string guidWithoutDashes = Guid.NewGuid().ToString(“n”);
//Console.WriteLine(“Guid without :- ” + guidWithoutDashes);
var chars1 = new char[numberOfChar];
var random = new Random();
for (int i = 0; i < chars.Length; i++)
{
chars[i] = guidWithoutDashes[random.Next(guidWithoutDashes.Length)];
}
//Console.WriteLine(“Random password is:- ” + new string(chars));
return new string(chars);
}
xcgvdfgfg
No comments:
Post a Comment