chatr/ChatrServer/Chatr/Session.cs

42 lines
859 B
C#
Raw Permalink Normal View History

2022-08-24 11:34:56 +00:00
using System.Security.Cryptography;
using System;
namespace Tesses.Chatr.Server
{
public class Session
{
public Session()
{
SessionId="";
}
public static string GetNewId()
{
byte[] data= new byte[32];
RandomNumberGenerator.Create().GetBytes(data);
return Convert.ToBase64String(data) ;
}
public string PrettyName {get;set;}
public DateTime Created {get;set;}
public long Id {get;set;}
public string SessionId {get;set;}
public long UserId {get;set;}
public bool RememberMe {get;set;}
public DateTime Expires {get;set;}
public string GetPrettyName()
{
if(string.IsNullOrWhiteSpace(PrettyName))
{
return $"Device {Created.ToShortTimeString()} on {Created.ToShortDateString()}";
}
return PrettyName;
}
}
}