-
Notifications
You must be signed in to change notification settings - Fork 16
/
CreateAccountParameterValidator.cs
56 lines (43 loc) · 1.59 KB
/
CreateAccountParameterValidator.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
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
using System.Linq;
using AutomaticTypeMapper;
namespace EOLib.Domain.Account
{
[AutoMappedType]
public class CreateAccountParameterValidator : ICreateAccountParameterValidator
{
private const string ValidEmailRegex = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b";
public bool AccountNameIsNotLongEnough(string account)
{
return account.Length < 4;
}
public bool AccountNameIsTooObvious(string account)
{
return account.Distinct().Count() < 3;
}
public bool PasswordMismatch(string input, string confirm)
{
return input != confirm;
}
public bool PasswordIsTooShort(string password)
{
return password.Length < 6;
}
public bool PasswordIsTooObvious(string password)
{
return password.Distinct().Count() < 3;
}
public bool EmailIsInvalid(string email)
{
return !System.Text.RegularExpressions.Regex.IsMatch(email.ToLowerInvariant(), ValidEmailRegex);
}
}
public interface ICreateAccountParameterValidator
{
bool AccountNameIsNotLongEnough(string account);
bool AccountNameIsTooObvious(string account);
bool PasswordMismatch(string input, string confirm);
bool PasswordIsTooShort(string password);
bool PasswordIsTooObvious(string password);
bool EmailIsInvalid(string email);
}
}