Skip to main content

C# Random Password Generator for ASP.NET Core & ASP.NET MVC Identity Framework

Yesterday I had to create a C# method that creates a random generated password in C#. Before committing into it I spent some minutes surfing the web, trying to find something I could use. I stumbled upon this 2006 post from Mads Kristensen, which is a guy I seriously love for all the great work he did with some incredibly useful Visual Studio extensions such as Web Essentials, Web Compiler, ASP.NET Core Web Templates – and much more.

However, the function I found in that post didn’t help me much, because it had no way to ensure any strong-password requisite other than the minimum required length: more specifically, I need to generate password with at least one uppercase & lowercase letter, digit and non-alphanumeric character – and also a certain amount of unique characters. The random password generated against the Mads function could have them or not, depending on the randomness: that simply won’t do in my scenario, since I had to deal with the UserManager.CreateUserAsync(username, password)  method of the Microsoft.AspNetCore.Identity  namespace, which utterly crashes whenever the password isn’t strong enough.

Read More

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

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!

Read More

Strip out numeric or non-numeric characters in string with ASP.NET C#

If you’re working with ASP.NET C# and you’re looking for something that could strip out numeric or non-numeric characters from a string, you might find these helper methods useful enough.

I wrote these methods to give an additional answer to this StackOverflow question, mostly because the accepted one didn’t handle null values: the behaviour of each one of them is well-documented within the <summary>  text, hence there’s nothing to explain here.

If you like them, feel free to leave a comment!

 

Programmatically convert MS Word DOC and DOCX files to PDF in ASP.NET C#

Who never had the urge to convert one or more MS Word DOC and DOCX files into a PDF at least once? Truth to be told, it wasn’t that trivial back in the day: until the release of Office 2010, when the PDF extension appeared among the various  formats supported by the Save As… command, using Ghostscript-based software or installing PDF printer drivers was the only way to go.

After Office 2010 the problem was finally solved even for the average user, with the sole exception that he still has to have MS Office installed on his machine. Those who didn’t have it can continue to use the aforementioned free alternatives ond purchase a software that will take care of the job for them.

What about doing that in a programmatic approach? What if we are developing a C# application and we need to convert some DOC or DOCX files into PDF, thus making then available to download without giving the source document to the users, possibly without having to waste an Office license to our web server/web publishing machine?

Read More

How to open and edit a Word DOC or DOCX file from FileSystem or Byte array in C#

If you’re working with ASP.NET C# and you need to open, edit or otherwise access a Microsoft Word DOC or DOCX file, you can easily do that using the Microsoft.Office.Interop.Word library package. This post explains how to do so: you might find it useful in case you need to perform such task or whenever you want to read some insights regarding the process.

Introducing Interop.Word

To access the namespace from your ASP.NET project you have two main choices:

Needless to say, you should really go for the second option, but we’ll leave that to you.

Read More

Close