Introduction:
Sometimes we need to generate random passwords for users. In this small article we will see two techniques that will generate unique passwords.
Using GUID:
The first method of Generating unique password is by using the System.Guid class.
Making custom method to Generate Unique Passwords:
If you want to make your own custom method that generates random passwords than you can use the method below:
string alphabets = "abcdefghijklmnopqrstuvwxyz"; string numbers = "01234567890123456789012345"; StringBuilder password = new StringBuilder(); Random r = new Random(); for(int j=0; j<=20;j++) { for(int i=0;i<=5;i++) { password.Append(alphabets[r.Next(alphabets.Length)]); password.Append(numbers[r.Next(numbers.Length)]); } Response.Write(password.ToString()); password.Remove(0,password.Length);
} |
The above method will generate passwords which will be the combination of alphabets and numbers.
I hope you like this article, happy coding !