Password Generator for C#

Free online password generator with C# code examples

Working with password generator in C#? Our free online password generator helps C# developers format, validate, and process data instantly. Below you will find C# code examples using System.Security.Cryptography (built-in) so you can achieve the same result programmatically in your own projects.

Try the Password Generator Online

Use our free Password Generator directly in your browser — no setup required.

Open Password Generator

C# Code Example

using System.Security.Cryptography;

string GeneratePassword(int length = 20)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
    var password = new char[length];
    for (int i = 0; i < length; i++)
    {
        password[i] = chars[RandomNumberGenerator.GetInt32(chars.Length)];
    }
    return new string(password);
}

Console.WriteLine(GeneratePassword(20));

Quick Setup

Library: System.Security.Cryptography (built-in)
// Built-in — no package needed

C# Tips & Best Practices

  • RandomNumberGenerator.GetInt32 is cryptographically secure
  • Available since .NET 6 — replaces RNGCryptoServiceProvider
  • Never use System.Random for password generation

Frequently Asked Questions

Password Generator in Other Languages

More C# Tools