邮箱正则配置到配置文件
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
|
||||
public static class IRCEmailPasswordHelper
|
||||
{
|
||||
@@ -74,4 +77,56 @@ public static class IRCEmailPasswordHelper
|
||||
// 随机打乱密码字符顺序
|
||||
return new string(password.OrderBy(_ => Random.Next()).ToArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://learn.microsoft.com/zh-cn/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format
|
||||
/// <summary>
|
||||
/// 微软官方邮件验证 很宽松
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidEmail(string email)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
// Normalize the domain
|
||||
email = Regex.Replace(email, @"(@)(.+)$", DomainMapper,
|
||||
RegexOptions.None, TimeSpan.FromMilliseconds(200));
|
||||
|
||||
// Examines the domain part of the email and normalizes it.
|
||||
string DomainMapper(Match match)
|
||||
{
|
||||
// Use IdnMapping class to convert Unicode domain names.
|
||||
var idn = new IdnMapping();
|
||||
|
||||
// Pull out and process domain name (throws ArgumentException on invalid)
|
||||
string domainName = idn.GetAscii(match.Groups[2].Value);
|
||||
|
||||
return match.Groups[1].Value + domainName;
|
||||
}
|
||||
}
|
||||
catch (RegexMatchTimeoutException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Regex.IsMatch(email,
|
||||
@"^[^@\s]+@[^@\s]+\.[^@\s]+$",
|
||||
RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
|
||||
}
|
||||
catch (RegexMatchTimeoutException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class AWSTempToken
|
||||
public string SecretAccessKey { get; set; }
|
||||
public string BucketName { get; set; }
|
||||
public string ViewEndpoint { get; set; }
|
||||
public DateTime Expiration { get; set; }
|
||||
public DateTime? Expiration { get; set; }
|
||||
}
|
||||
|
||||
public enum ObjectStoreUse
|
||||
|
||||
Reference in New Issue
Block a user