-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cs
More file actions
32 lines (24 loc) · 861 Bytes
/
Token.cs
File metadata and controls
32 lines (24 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace Mini_Securonix_API;
public class Token
{
public string id {get;}
public string username {get;}
public DateTime expirationdate {get;set;}
public Token(string u, int validity=365) {
Random random = new Random();
// Set token username
username = u;
// Adjust expirationdate by displayed timespan
expirationdate = DateTime.Now + new TimeSpan(validity, 0, 0, 0);
// "randomly" generate 16 hex values
id = "";
for(int i = 0; i < 32; i++)
id += random.Next(16).ToString("X");
}
public string PrettyString() {
// String format in hex
// ########-####-####-####-############
return $"{id.Substring(0,8)}-{id.Substring(8,4)}-{id.Substring(12,4)}-"
+ $"{id.Substring(16,4)}-{id.Substring(20,12)}";
}
}