WebProfile.Key(serverId, account) = serverId/ + 32 lowercase hex of SHA-256 over the server id and the trimmed, lower-cased account; null without an account. Keys pass ServerWebOpen.IsValidProfileKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
1.1 KiB
C#
23 lines
1.1 KiB
C#
// The per-account web profile key: each account gets its own WebView2 profile folder, so website
|
|
// cookies never cross accounts. Pure, so RynthServerPack.Tests compiles it directly.
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace RynthCore.Plugin.RynthDreamWeave;
|
|
|
|
internal static class WebProfile
|
|
{
|
|
/// <summary>
|
|
/// "serverId/" plus the first 32 lowercase hex chars of SHA-256(UTF-8(serverId + "\n" + the trimmed,
|
|
/// lower-cased account)); null when there is no account. The server id (not the world name) keeps
|
|
/// one site's cookies together. The hash keeps the account name out of the folder name. The result
|
|
/// passes ServerWebOpen.IsValidProfileKey when serverId matches ^[a-z0-9-]{1,32}$.
|
|
/// </summary>
|
|
public static string? Key(string serverId, string? account)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(account)) return null;
|
|
byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes(serverId + "\n" + account.Trim().ToLowerInvariant()));
|
|
return serverId + "/" + Convert.ToHexString(hash).ToLowerInvariant().Substring(0, 32);
|
|
}
|
|
}
|