-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathValidationResult.cs
More file actions
80 lines (70 loc) · 1.79 KB
/
ValidationResult.cs
File metadata and controls
80 lines (70 loc) · 1.79 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
namespace Waher.Security.TOTP
{
/// <summary>
/// Validation result enumeration.
/// </summary>
public enum OtpValidationResult
{
/// <summary>
/// Pass Code valid.
/// </summary>
Valid,
/// <summary>
/// Pass Code invalid.
/// </summary>
Invalid,
/// <summary>
/// Counter provided invalid.
/// </summary>
CounterInvalid,
/// <summary>
/// Endpoint is temporarily blocked.
/// </summary>
TemporaryBlock,
/// <summary>
/// Endpoint is permanently blocked.
/// </summary>
PermanentBlock
}
/// <summary>
/// Contains information of a HOTP or TOTP validation attempt.
/// </summary>
public class ValidationResult
{
private readonly OtpValidationResult result;
private readonly DateTime blockedUntil;
/// <summary>
/// Contains information of a HOTP or TOTP validation attempt.
/// </summary>
/// <param name="Ok">If code was valid or not.</param>
public ValidationResult(bool Ok)
{
this.result = Ok ? OtpValidationResult.Valid : OtpValidationResult.Invalid;
this.blockedUntil = DateTime.MinValue;
}
/// <summary>
/// Contains information of a HOTP or TOTP validation attempt.
/// </summary>
/// <param name="BlockedUntil">Timestamp of block.</param>
public ValidationResult(DateTime BlockedUntil)
{
this.result = BlockedUntil == DateTime.MaxValue ?
OtpValidationResult.PermanentBlock :
OtpValidationResult.TemporaryBlock;
this.blockedUntil = BlockedUntil;
}
/// <summary>
/// Contains information of a HOTP or TOTP validation attempt.
/// </summary>
public ValidationResult()
{
this.result = OtpValidationResult.CounterInvalid;
this.blockedUntil = DateTime.MinValue;
}
/// <summary>
/// Validation result.
/// </summary>
public OtpValidationResult Result => this.result;
}
}