Most of the web application consists of login pages which authenticate the user based on username and password. For the registoration purposes you might need to create a random password and email the password to the user and than the user has to use that password to log to the website. In this article we will see how we can create a random password.


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++)


The above method will generate passwords which will be the combination of alphabets and numbers.

I hope you like this article, happy coding !