All Projects → Darkseal → PasswordGenerator

Darkseal / PasswordGenerator

Licence: Apache-2.0 License
A simple C# helper class for ASP.NET Core to generate a random password with custom strength requirements: min length, uppercase, lowercase, digits & more

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to PasswordGenerator

Dynamic-User-Defined-Dashboards-Asp-Net-Core
Complete Solution for Dynamically Created User-Defined Dashboards using Asp.Net Core
Stars: ✭ 32 (+18.52%)
Mutual labels:  asp-net-core, asp-net
WebDAVServerSamples
WebDAV, CalDAV & CardDAV server examples in C# and VB based on IT Hit WebDAV Server Engine for .NET
Stars: ✭ 39 (+44.44%)
Mutual labels:  asp-net-core, asp-net
vctr
vctr is a self hosted short link management tool.
Stars: ✭ 14 (-48.15%)
Mutual labels:  asp-net-core, asp-net
Asp-net-Core-Project-with-Admin-Template-Setup
AdminLTE Template Setup with Asp.net Core MVC 2.1 Project
Stars: ✭ 50 (+85.19%)
Mutual labels:  asp-net-core, asp-net
genpw
Password Generator
Stars: ✭ 32 (+18.52%)
Mutual labels:  password-generator, password
StormReport
🌀 Library - Create your reports using only annotations
Stars: ✭ 17 (-37.04%)
Mutual labels:  asp-net-core, asp-net
LAPSforMac
Local Administrator Password Solution for Mac
Stars: ✭ 29 (+7.41%)
Mutual labels:  password-generator, password
AspNetCore-Dynamic-Permission
Dynamic Permission Samples in ASP.NET Core and ASP.NET MVC 5.
Stars: ✭ 19 (-29.63%)
Mutual labels:  asp-net-core, asp-net
UrlBase64
A standards-compliant implementation of web/url-safe base64 encoding and decoding for .NET targets
Stars: ✭ 25 (-7.41%)
Mutual labels:  asp-net-core, asp-net
OormiPass
Free open source cross platform password manager
Stars: ✭ 50 (+85.19%)
Mutual labels:  password-generator, password
X.Web.Sitemap
Simple sitemap generator for .NET
Stars: ✭ 66 (+144.44%)
Mutual labels:  asp-net-core, asp-net
coreddd
A set of open-source .NET libraries helping with domain-driven design (DDD) and CQRS
Stars: ✭ 68 (+151.85%)
Mutual labels:  asp-net-core, asp-net
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+222.22%)
Mutual labels:  asp-net-core, asp-net
gpgpwd
Moved to GitLab
Stars: ✭ 22 (-18.52%)
Mutual labels:  password-generator, password
Cake-Shop
A sample Cake Shop Website built with ASP.NET Core (Multi-Page Application)
Stars: ✭ 44 (+62.96%)
Mutual labels:  asp-net-core, asp-net
FlowerPassword
🌸花密,不一样的密码管理器
Stars: ✭ 37 (+37.04%)
Mutual labels:  password-generator, password
password-list
Password lists with top passwords to optimize bruteforce attacks
Stars: ✭ 174 (+544.44%)
Mutual labels:  password-generator, password
webpassgen
Simple web-based password generator
Stars: ✭ 111 (+311.11%)
Mutual labels:  password-generator, password
PasswordX
Offline password manager for iOS/macOS
Stars: ✭ 26 (-3.7%)
Mutual labels:  password-generator, password
lockd
Generate strong passwords and save them in Keychain. Made with SwiftUI
Stars: ✭ 38 (+40.74%)
Mutual labels:  password-generator, password

PasswordGenerator

A simple C# helper class for ASP.NET Core to generate a random password with custom strength requirements: min length, uppercase, lowercase, digits & more

Introduction

Some time ago I had to implement 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 a bunch of other great stuff.

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.

Eventually, I ended up coding my own helper class - just like Mads Kristensen more than 11 years ago.

Usage

As you can see by looking at the source code, the class takes a PasswordOptions object as parameter, which is shipped by the Microsoft.AspNetCore.Identity assembly, but you can easily replace it with a two int - four bool parameter group or POCO class if you don't have that package installed. In the likely case you have it in your ASP.NET Core project, you can use the exact same object used in the ConfigureService method of the Startup class when defining the password requirements:

// Add ASP.NET Identity support
services.AddIdentity<ApplicationUser, IdentityRole>(
    opts =>
{
    opts.Password.RequireDigit = true;
    opts.Password.RequireLowercase = true;
    opts.Password.RequireUppercase = true;
    opts.Password.RequireNonAlphanumeric = false;
    opts.Password.RequiredLength = 8;
})
.AddEntityFrameworkStores<ApplicationDbContext>();

UPDATE: as of July 2018, the PasswordOptions native support has been removed to avoid the required dependency to the Microsoft.AspNetCore.Identity class: now the class has standard parameters (two int, four boolean) having the same name of the corresponding PasswordOptions properties.

That's it for now: hope you'll like it!

Security considerations

The password randomness is calculated using a CryptoRandom class that mimics the standard Random class in the .NET Framework, replacing its standard (non-secure) behaviour with a cryptographic random number generator. The CryptoRandom class has been taken from IdentityModel.

In the GitHub project you'll also find an alternative CryptoRandom implementation (CryptoRandom2), which has been taken from here (credits to Stephen Toub, Shawn Farkas and Markus Olsson). If you want to use the alternative implementation, just rename the CryptoRandom2.cs file and class to CryptoRandom, replacing the previous one - or just instantiate a CryptoRandom2 object in the PasswordGenerator.cs file.

Online Resources

Additional References

If you need a C# helper function to check for strong passwords, don't forget to also read this post.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].