tesses-cms/Tesses.CMS/CSRF.cs

29 lines
707 B
C#

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);
}
}
}