mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-06-05 14:25:17 -04:00
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace API.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user