Files
Chronos/src/Titano.Server/Security/Accounts.cs
T
Claude c78747053e feat(server): API v1 with auth, uploads, sync, jobs, render nodes and events
- Security: PBKDF2-SHA512 (210,000 iterations) hashes, opaque bearer tokens
  stored as SHA-256 with sliding expiry and revocation, HttpOnly/Secure/
  SameSite=Strict admin cookie with a session-bound CSRF token, sign-in rate
  limit and lockout, role/permission metadata on every endpoint, audit log,
  first-run administrator bootstrap.
- Sequences with keyset paging, ETags and settings_version conflicts; sync
  manifest; frames, proxies, thumbnails and exports streamed with Range.
- Chunked resumable uploads with hash short-circuit, quota and disk checks,
  staging on the archive volume, SHA-256 verification and IArchiveIngest.
- Job engine host, jobs API, render nodes with heartbeat timeout and
  reassignment, WebSocket events, LAN discovery beacon, upload cleanup.
- Windows service host over advapi32 (--service, --install-service,
  --uninstall-service); fails fast without the archive module services.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 11:32:19 +00:00

36 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Titano.Core.Model;
namespace Titano.Server.Security;
/// <summary>Account rules shared by bootstrap, sign-in and user management.</summary>
public static class Accounts
{
public const int MaxUsernameLength = 64;
/// <summary>Letters, digits, dot, dash and underscore; 1–64 characters.</summary>
public static bool IsValidUsername(string? name) =>
name is { Length: > 0 and <= MaxUsernameLength } && name.All(c => char.IsAsciiLetterOrDigit(c) || c is '.' or '-' or '_');
/// <summary>The case-insensitive key of a user name (lock-out bookkeeping).</summary>
public static string Key(string? name) => (name ?? string.Empty).Trim().ToLowerInvariant();
/// <summary>The role's default permissions with the render-node right granted or withheld explicitly.</summary>
public static Permissions PermissionsFor(UserRole role, bool renderNode) =>
(RolePermissions.Default(role) & ~Permissions.RenderNode) | (renderNode ? Permissions.RenderNode : Permissions.None);
/// <summary>Parses a role name (admin, editor, uploader, viewer); numbers are not accepted.</summary>
public static bool TryParseRole(string? text, out UserRole role)
{
foreach (var candidate in Enum.GetValues<UserRole>())
{
if (string.Equals(candidate.ToString(), text, StringComparison.OrdinalIgnoreCase))
{
role = candidate;
return true;
}
}
role = default;
return false;
}
}