Site icon Ryadel

PasswordCheck - A small C# class to calculate password strength and implement custom password policies in ASP.NET

Classe ASP.NET C# per il controllo e il calcolo formale del Codice Fiscale

If you're looking for a decent password strength control implementation for ASP.NET C# you could find this class I made a while ago useful enough. After all these years I'm still using it in a number of projects, from the good-old ASP.NET ASPX Forms to the new ASP.NET Core MVC applications.

The class can be used to perform basically all the required checks in a very customizable way: minimum length, maximum length, digit/numbers, special characters and so on. It features a PasswordStrength enum (and a GetPasswordStrength method) which you can use to calculate the average strength of any given password: it can be handy for general-purpose scenarios, when you don't have to implement a given password policy. In case you have to do that, you can use the helper methods instead and combine them to suit your needs as shown in the sample implementation provided within the IsStrongPassword method - which is the one I'm still using in most cases.

The methods are quite self-explanatory, so there isn't much more to say: if you like the class, feel free to leave a feedback in the comment section below!

It's worth noting that one of the methods (the one using PasswordOptions as a parameter) requires a reference to the using Microsoft.AspNetCore.Identity namespace: it will come very handy when using the ASP.NET Core Identity Framework to check the password validity at the server-side in some specific scenarios, such as new users registrations. If we don't want - or need - to add the Identity Framework to your project, we can just comment out that method and use the generic overload below.

 

Exit mobile version