Kavita/Kavita.Common/Helpers/AuthKeyHelper.cs
Fesaa c62b20f54b
BE Tech Debt (#4497)
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com>
Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
2026-03-07 10:04:08 -08:00

27 lines
799 B
C#

using System;
using System.Security.Cryptography;
namespace Kavita.Common.Helpers;
public static class AuthKeyHelper
{
private const string AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
public const int MinKeyLength = 8;
public const int MaxKeyLength = 32;
public const string OpdsKeyName = "opds";
public const string ImageOnlyKeyName = "image-only";
public static string GenerateKey(int keyLength = 8)
{
if (keyLength is < MinKeyLength or > MaxKeyLength)
{
throw new ArgumentOutOfRangeException(nameof(keyLength),
$"Key length must be between {MinKeyLength} and {MaxKeyLength}");
}
return RandomNumberGenerator.GetString(AllowedCharacters, keyLength);
}
}