2022-03-15 18:00:53 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
//
|
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
// any third-party rights.
|
|
|
|
//
|
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
//
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
//
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
//
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
//
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-01-31 08:30:08 +00:00
|
|
|
using Constants = ASC.Core.Users.Constants;
|
2020-01-17 13:58:26 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Core.Users;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Web studio user manager helper
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
[Scope]
|
|
|
|
public sealed class UserManagerWrapper
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
private StudioNotifyService StudioNotifyService { get; }
|
|
|
|
private UserManager UserManager { get; }
|
|
|
|
private SecurityContext SecurityContext { get; }
|
|
|
|
private MessageService MessageService { get; }
|
|
|
|
private CustomNamingPeople CustomNamingPeople { get; }
|
|
|
|
private TenantUtil TenantUtil { get; }
|
|
|
|
private CoreBaseSettings CoreBaseSettings { get; }
|
|
|
|
private IPSecurity.IPSecurity IPSecurity { get; }
|
|
|
|
private DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
|
|
|
|
private SettingsManager SettingsManager { get; }
|
|
|
|
private UserFormatter UserFormatter { get; }
|
|
|
|
|
|
|
|
public UserManagerWrapper(
|
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
UserManager userManager,
|
|
|
|
SecurityContext securityContext,
|
|
|
|
MessageService messageService,
|
|
|
|
CustomNamingPeople customNamingPeople,
|
|
|
|
TenantUtil tenantUtil,
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
IPSecurity.IPSecurity iPSecurity,
|
|
|
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
|
|
|
SettingsManager settingsManager,
|
|
|
|
UserFormatter userFormatter)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService = studioNotifyService;
|
|
|
|
UserManager = userManager;
|
|
|
|
SecurityContext = securityContext;
|
|
|
|
MessageService = messageService;
|
|
|
|
CustomNamingPeople = customNamingPeople;
|
|
|
|
TenantUtil = tenantUtil;
|
|
|
|
CoreBaseSettings = coreBaseSettings;
|
|
|
|
IPSecurity = iPSecurity;
|
|
|
|
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
|
|
|
SettingsManager = settingsManager;
|
|
|
|
UserFormatter = userFormatter;
|
|
|
|
}
|
2019-08-01 08:47:15 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
private bool TestUniqueUserName(string uniqueName)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(uniqueName))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return false;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return Equals(UserManager.GetUserByUserName(uniqueName), Constants.LostUser);
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
private string MakeUniqueName(UserInfo userInfo)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(userInfo.Email))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
throw new ArgumentException(Resource.ErrorEmailEmpty, nameof(userInfo));
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
var uniqueName = new MailAddress(userInfo.Email).User;
|
|
|
|
var startUniqueName = uniqueName;
|
|
|
|
var i = 0;
|
|
|
|
while (!TestUniqueUserName(uniqueName))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
uniqueName = $"{startUniqueName}{(++i).ToString(CultureInfo.InvariantCulture)}";
|
|
|
|
}
|
|
|
|
return uniqueName;
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public bool CheckUniqueEmail(Guid userId, string email)
|
|
|
|
{
|
|
|
|
var foundUser = UserManager.GetUserByEmail(email);
|
|
|
|
return Equals(foundUser, Constants.LostUser) || foundUser.Id == userId;
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public UserInfo AddUser(UserInfo userInfo, string passwordHash, bool afterInvite = false, bool notify = true, bool isVisitor = false, bool fromInviteLink = false, bool makeUniqueName = true)
|
|
|
|
{
|
|
|
|
ArgumentNullException.ThrowIfNull(userInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!UserFormatter.IsValidUserName(userInfo.FirstName, userInfo.LastName))
|
|
|
|
{
|
|
|
|
throw new Exception(Resource.ErrorIncorrectUserName);
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!CheckUniqueEmail(userInfo.Id, userInfo.Email))
|
|
|
|
{
|
|
|
|
throw new Exception(CustomNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (makeUniqueName)
|
|
|
|
{
|
|
|
|
userInfo.UserName = MakeUniqueName(userInfo);
|
|
|
|
}
|
|
|
|
if (!userInfo.WorkFromDate.HasValue)
|
|
|
|
{
|
|
|
|
userInfo.WorkFromDate = TenantUtil.DateTimeNow();
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!CoreBaseSettings.Personal && !fromInviteLink)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
userInfo.ActivationStatus = !afterInvite ? EmployeeActivationStatus.Pending : EmployeeActivationStatus.Activated;
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
var newUserInfo = UserManager.SaveUserInfo(userInfo);
|
|
|
|
SecurityContext.SetUserPasswordHash(newUserInfo.Id, passwordHash);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (CoreBaseSettings.Personal)
|
|
|
|
{
|
|
|
|
StudioNotifyService.SendUserWelcomePersonal(newUserInfo);
|
|
|
|
return newUserInfo;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2020-09-18 07:59:23 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if ((newUserInfo.Status & EmployeeStatus.Active) == EmployeeStatus.Active && notify)
|
2019-09-23 12:20:08 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
//NOTE: Notify user only if it's active
|
|
|
|
if (afterInvite)
|
2019-09-23 12:20:08 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
if (isVisitor)
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.GuestInfoAddedAfterInvite(newUserInfo);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
else
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.UserInfoAddedAfterInvite(newUserInfo);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2019-09-23 12:20:08 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (fromInviteLink)
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.SendEmailActivationInstructions(newUserInfo, newUserInfo.Email);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2019-09-23 12:20:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
//Send user invite
|
|
|
|
if (isVisitor)
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.GuestInfoActivation(newUserInfo);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
else
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.UserInfoActivation(newUserInfo);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-09-23 12:20:08 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (isVisitor)
|
|
|
|
{
|
|
|
|
UserManager.AddUserIntoGroup(newUserInfo.Id, Constants.GroupVisitor.ID);
|
2020-09-18 07:59:23 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return newUserInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Password
|
|
|
|
|
|
|
|
public void CheckPasswordPolicy(string password)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
2020-09-18 07:59:23 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
throw new Exception(Resource.ErrorPasswordEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
var passwordSettingsObj = SettingsManager.Load<PasswordSettings>();
|
2020-09-18 07:59:23 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!CheckPasswordRegex(passwordSettingsObj, password))
|
|
|
|
{
|
|
|
|
throw new Exception(GenerateErrorMessage(passwordSettingsObj));
|
2019-09-23 12:20:08 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string GetPasswordRegex(PasswordSettings passwordSettings)
|
|
|
|
{
|
|
|
|
var pwdBuilder = new StringBuilder();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (CoreBaseSettings.CustomMode)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"^(?=.*[a-z]{0,})");
|
|
|
|
|
|
|
|
if (passwordSettings.Digits)
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\d)");
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.UpperCase)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[A-Z])");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.SpecSymbols)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[_\-.~!$^*()=|])");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
pwdBuilder.Append(@"[0-9a-zA-Z_\-.~!$^*()=|]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pwdBuilder.Append(@"^(?=.*\p{Ll}{0,})");
|
|
|
|
|
|
|
|
if (passwordSettings.Digits)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\d)");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
if (passwordSettings.UpperCase)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\p{Lu})");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
if (passwordSettings.SpecSymbols)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[\W])");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append('.');
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
pwdBuilder.Append('{');
|
|
|
|
pwdBuilder.Append(passwordSettings.MinLength);
|
|
|
|
pwdBuilder.Append(',');
|
|
|
|
pwdBuilder.Append(PasswordSettings.MaxLength);
|
|
|
|
pwdBuilder.Append(@"}$");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return pwdBuilder.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckPasswordRegex(PasswordSettings passwordSettings, string password)
|
|
|
|
{
|
|
|
|
var passwordRegex = GetPasswordRegex(passwordSettings);
|
|
|
|
|
|
|
|
return new Regex(passwordRegex).IsMatch(password);
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string SendUserPassword(string email)
|
|
|
|
{
|
|
|
|
email = (email ?? "").Trim();
|
|
|
|
if (!email.TestEmailRegex())
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
throw new ArgumentNullException(nameof(email), Resource.ErrorNotCorrectEmail);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!IPSecurity.Verify())
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
throw new Exception(Resource.ErrorAccessRestricted);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
var userInfo = UserManager.GetUserByEmail(email);
|
|
|
|
if (!UserManager.UserExists(userInfo) || string.IsNullOrEmpty(userInfo.Email))
|
|
|
|
{
|
|
|
|
return string.Format(Resource.ErrorUserNotFoundByEmail, email);
|
|
|
|
}
|
|
|
|
if (userInfo.Status == EmployeeStatus.Terminated)
|
|
|
|
{
|
|
|
|
return Resource.ErrorDisabledProfile;
|
|
|
|
}
|
|
|
|
if (userInfo.IsLDAP())
|
|
|
|
{
|
|
|
|
return Resource.CouldNotRecoverPasswordForLdapUser;
|
|
|
|
}
|
|
|
|
if (userInfo.IsSSO())
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return Resource.CouldNotRecoverPasswordForSsoUser;
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
StudioNotifyService.UserPasswordChange(userInfo);
|
2022-03-17 15:01:39 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
var displayUserName = userInfo.DisplayUserName(false, DisplayUserSettingsHelper);
|
|
|
|
MessageService.Send(MessageAction.UserSentPasswordChangeInstructions, displayUserName);
|
2022-03-17 15:01:39 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GeneratePassword()
|
|
|
|
{
|
|
|
|
return Guid.NewGuid().ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static string GeneratePassword(int minLength, int maxLength, string noise)
|
|
|
|
{
|
|
|
|
var length = RandomNumberGenerator.GetInt32(minLength, maxLength + 1);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
var sb = new StringBuilder();
|
|
|
|
while (length-- > 0)
|
|
|
|
{
|
|
|
|
sb.Append(noise[RandomNumberGenerator.GetInt32(noise.Length - 1)]);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static string GenerateErrorMessage(PasswordSettings passwordSettings)
|
|
|
|
{
|
|
|
|
var error = new StringBuilder();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
error.Append($"{Resource.ErrorPasswordMessage} ");
|
|
|
|
error.AppendFormat(Resource.ErrorPasswordLength, passwordSettings.MinLength, PasswordSettings.MaxLength);
|
|
|
|
if (passwordSettings.UpperCase)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
error.AppendFormat($", {Resource.ErrorPasswordNoUpperCase}");
|
|
|
|
}
|
2022-03-17 15:01:39 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.Digits)
|
|
|
|
{
|
|
|
|
error.Append($", {Resource.ErrorPasswordNoDigits}");
|
|
|
|
}
|
2022-03-17 15:01:39 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.SpecSymbols)
|
|
|
|
{
|
|
|
|
error.Append($", {Resource.ErrorPasswordNoSpecialSymbols}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return error.ToString();
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetPasswordHelpMessage()
|
|
|
|
{
|
|
|
|
var info = new StringBuilder();
|
|
|
|
var passwordSettings = SettingsManager.Load<PasswordSettings>();
|
|
|
|
info.Append($"{Resource.ErrorPasswordMessageStart} ");
|
|
|
|
info.AppendFormat(Resource.ErrorPasswordLength, passwordSettings.MinLength, PasswordSettings.MaxLength);
|
|
|
|
if (passwordSettings.UpperCase)
|
|
|
|
{
|
|
|
|
info.Append($", {Resource.ErrorPasswordNoUpperCase}");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.Digits)
|
|
|
|
{
|
|
|
|
info.Append($", {Resource.ErrorPasswordNoDigits}");
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (passwordSettings.SpecSymbols)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
info.Append($", {Resource.ErrorPasswordNoSpecialSymbols}");
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
return info.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public static bool ValidateEmail(string email)
|
|
|
|
{
|
|
|
|
const string pattern = @"^(([^<>()[\]\\.,;:\s@\""]+"
|
|
|
|
+ @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
|
|
|
|
+ @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$";
|
|
|
|
const RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
|
|
|
|
return new Regex(pattern, options).IsMatch(email);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|