-
Notifications
You must be signed in to change notification settings - Fork 0
/
Security.cs
31 lines (27 loc) · 942 Bytes
/
Security.cs
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
namespace CardStorageRestAPI
{
public class AsciiIdentifier
{
private readonly string verifiedString;
public AsciiIdentifier(string str) {
// checking the input for permitted values
var trimmed = str.Trim();
// only A-Za-z0-9 and '_' and '-' are permitted
foreach (char c in trimmed) {
if (
(c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ||
(c == '-') || (c == '_')
)
continue;
throw new ArgumentException($"identifier contains characters that are not permitted. Only A-Za-z0-9 and '_' and '-' are permitted");
}
verifiedString = trimmed;
}
public override string ToString()
{
return this.verifiedString;
}
}
}