Random Password Generator in C#.NET
This blog is going to illustrate the Random Password Generator in the .NET Framework. The GeneratePassword method is used to generate a random password and is most commonly used for reset password and new or temporary password. It is a very easy to use method.
GeneratePassword() method will generate the password with specific length.
The following is a syntax for GeneratePassword method
Length (int): The password length
numberOfNonAlphanumericCharacters (int): Minimum no. of alphanumeric characters.
The following is a code snippet to generate a random password. Here length and nonAlphaNumeric values are passed to Membership.GeneratePassword() method. And the result has been assigned to the password textbox.
The following is an output of the above code. The password is generated based on the length and number of alphanumeric characters.
I hope this helps you. Keep coding.
The System.Web namespace, which includes the System.Web.Security.Membership.GeneratePassword(int length, int numberOfNonAlphanumericCharacters) method referenced in this article, is unsupported in .NET Core & .NET 5+.
ReplyDeleteThank you for your comment and bringing up an important point. You're absolutely right that the System.Web namespace, including the System.Web.Security.Membership.GeneratePassword method, is not supported in .NET Core and .NET 5+.
ReplyDeleteYou can use the RNGCryptoServiceProvider class to generate a random sequence of characters that can be combined to form a secure password