FloppyShelf.UserManagement
1.0.1
dotnet add package FloppyShelf.UserManagement --version 1.0.1
NuGet\Install-Package FloppyShelf.UserManagement -Version 1.0.1
<PackageReference Include="FloppyShelf.UserManagement" Version="1.0.1" />
<PackageVersion Include="FloppyShelf.UserManagement" Version="1.0.1" />
<PackageReference Include="FloppyShelf.UserManagement" />
paket add FloppyShelf.UserManagement --version 1.0.1
#r "nuget: FloppyShelf.UserManagement, 1.0.1"
#addin nuget:?package=FloppyShelf.UserManagement&version=1.0.1
#tool nuget:?package=FloppyShelf.UserManagement&version=1.0.1
FloppyShelf.UserManagement
C# library for generating unique usernames based on first and last names while ensuring consistency and availability. It is designed to be integrated into user management systems.
Features
- Generates unique usernames based on first and last names.
- Handles replacement rules for special characters (e.g., "Ä" becomes "Ae").
- Removes invalid characters (non-alphanumeric) from the username.
- Supports length constraints for the generated username.
- Handles username collisions with numeric suffixes.
- Reverses the order of names for additional variety in username generation.
- Easily configurable replacement rules.
Installation
Install via NuGet:
dotnet add package FloppyShelf.UserManagement
Or via the Package Manager:
Install-Package FloppyShelf.UserManagement
Usage
Basic Usage Example
The UniqueUsernameGenerator class allows you to generate unique usernames based on a user's first and last name. Below is an example of how to use the service in your project.
using FloppyShelf.UserManagement.Services;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Example replacement rules (optional)
var replacementRules = new Dictionary<string, string>
{
{ "Sch", "S" }, // Replace "Sch" with "S"
{ "Ä", "Ae" } // Replace "Ä" with "Ae"
};
// Initialize the username generator with replacement rules (optional)
var usernameGenerator = new UniqueUsernameGenerator(replacementRules);
// Set of existing usernames to avoid collision
var existingUsernames = new HashSet<string>
{
"johnsmith",
"janedoe"
};
try
{
// Generate a unique username
string firstName = "John";
string lastName = "Schmidt";
string uniqueUsername = usernameGenerator.GenerateUniqueUsername(firstName, lastName, 6, 12, existingUsernames);
Console.WriteLine($"Generated unique username: {uniqueUsername}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
Constructor
public UniqueUsernameGenerator(Dictionary<string, string> replacementRules = null);
- replacementRules (optional): A dictionary of string replacement rules to apply to the names before generating the username. If not provided, default rules are used.
Methods
GenerateUniqueUsername
public string GenerateUniqueUsername(string firstName, string lastName, int minLength, int maxLength, HashSet<string> existingUsernames);
- firstName: The first name of the user.
- lastName: The last name of the user.
- minLength: The minimum length of the generated username.
- maxLength: The maximum length of the generated username.
- existingUsernames: A set of existing usernames to avoid username collisions.
Returns: A unique username generated from the provided first and last names.
Throws:
- ArgumentException if the first or last name is empty or whitespace.
- ArgumentOutOfRangeException if the provided length constraints are invalid.
- InvalidOperationException if no unique username can be generated.
Replacement Rules
By default, the service includes the following replacement rules:
- "Sch" → "S"
- "sch" → "s"
- "Ä" → "Ae"
- "Ö" → "Oe"
- "Ü" → "Ue"
- "ä" → "ae"
- "ö" → "oe"
- "ü" → "ue"
- "ß" → "ss"
You can customize these rules by providing a dictionary of replacement rules when initializing the UniqueUsernameGenerator class.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 89 | 3/29/2025 |