diff options
| author | Tim <contact@bytim.eu> | 2025-12-25 19:59:26 +0100 |
|---|---|---|
| committer | Tim <contact@bytim.eu> | 2025-12-25 19:59:26 +0100 |
| commit | 771b949618bb4e07c09c2fb94a7f92e13f471b9e (patch) | |
| tree | 88c2e69fc14bef91e414c605712420437cc92ccf /ShareGuard.Web/DbModels/Link.cs | |
Diffstat (limited to 'ShareGuard.Web/DbModels/Link.cs')
| -rw-r--r-- | ShareGuard.Web/DbModels/Link.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ShareGuard.Web/DbModels/Link.cs b/ShareGuard.Web/DbModels/Link.cs new file mode 100644 index 0000000..0cd66ac --- /dev/null +++ b/ShareGuard.Web/DbModels/Link.cs @@ -0,0 +1,24 @@ +namespace ShareGuard.Web.DbModels; + +public class Link +{ + private static readonly string _tokenChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + private static readonly Random _random = new(); + public int Id { get; set; } + public string Token { get; set; } + public string Name { get; set; } + public string IpAddress { get; set; } + public string? PeerPublicKey { get; set; } + + public static string GenerateToken(Database database) + { + var token = ""; + while (token == "" || database.Links.Any(link => link.Token == token)) + { + token = ""; + for (var i = 0; i < 10; i++) token += _tokenChars[_random.Next(_tokenChars.Length)]; + } + + return token; + } +}
\ No newline at end of file |
