refactor: extract DI, helpers from Program.cs into extension classes
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Nexus.Api.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for password generation and name construction.
|
||||
/// </summary>
|
||||
public static class PasswordHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a cryptographically random temporary password (30 chars, URL-safe base64).
|
||||
/// </summary>
|
||||
public static string GenerateTemporaryPassword()
|
||||
=> Convert.ToBase64String(RandomNumberGenerator.GetBytes(18))
|
||||
.TrimEnd('=')
|
||||
.Replace('+', '-')
|
||||
.Replace('/', '_');
|
||||
|
||||
/// <summary>
|
||||
/// Builds a human-readable display name from an email address.
|
||||
/// </summary>
|
||||
public static string BuildOwnerDisplayName(string email)
|
||||
{
|
||||
var localPart = email.Split('@', 2)[0].Trim();
|
||||
if (string.IsNullOrWhiteSpace(localPart)) return "Owner";
|
||||
|
||||
var words = localPart
|
||||
.Replace('.', ' ')
|
||||
.Replace('_', ' ')
|
||||
.Replace('-', ' ')
|
||||
.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(word => char.ToUpperInvariant(word[0]) + word[1..].ToLowerInvariant());
|
||||
|
||||
var displayName = string.Join(' ', words);
|
||||
return string.IsNullOrWhiteSpace(displayName) ? "Owner" : displayName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user