tesses-cms/Tesses.CMS/CSRF.cs

29 lines
707 B
C#
Raw Permalink Normal View History

2024-07-28 22:59:28 +00:00
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using Newtonsoft.Json;
namespace Tesses.CMS
{
public class CSRF
{
public long UserId {get;set;}
public DateTime Expires {get;set;}
public string Cookie {get;set;}
public string CSRFToken {get;set;}
public CSRF(long userId, string cookie)
{
UserId = userId;
Cookie = cookie;
Expires = DateTime.Now.AddMinutes(10);
byte[] data = new byte[32];
using(var rng=RandomNumberGenerator.Create())
rng.GetNonZeroBytes(data);
CSRFToken = Convert.ToBase64String(data);
}
}
}