2019-06-14 16:14:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
*
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL 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 more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Net.Mail;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
2020-01-17 13:58:26 +00:00
|
|
|
|
2020-02-17 08:58:14 +00:00
|
|
|
using ASC.Common;
|
2019-06-14 16:14:24 +00:00
|
|
|
using ASC.Core;
|
2019-10-31 13:54:43 +00:00
|
|
|
using ASC.Core.Common.Settings;
|
2019-06-14 16:14:24 +00:00
|
|
|
using ASC.Core.Tenants;
|
|
|
|
using ASC.Core.Users;
|
|
|
|
using ASC.MessagingSystem;
|
|
|
|
using ASC.Web.Core.PublicResources;
|
|
|
|
using ASC.Web.Core.Utility;
|
|
|
|
using ASC.Web.Studio.Core.Notify;
|
2020-01-17 13:58:26 +00:00
|
|
|
|
2019-06-14 16:14:24 +00:00
|
|
|
namespace ASC.Web.Core.Users
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Web studio user manager helper
|
|
|
|
/// </summary>
|
2020-10-19 15:53:15 +00:00
|
|
|
///
|
|
|
|
[Scope]
|
2019-06-14 16:14:24 +00:00
|
|
|
public sealed class UserManagerWrapper
|
|
|
|
{
|
2020-08-12 09:58:08 +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; }
|
2019-09-12 11:34:58 +00:00
|
|
|
|
|
|
|
public UserManagerWrapper(
|
2019-10-31 11:28:30 +00:00
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
UserManager userManager,
|
|
|
|
SecurityContext securityContext,
|
2019-09-20 15:53:27 +00:00
|
|
|
MessageService messageService,
|
2019-09-17 12:42:32 +00:00
|
|
|
CustomNamingPeople customNamingPeople,
|
2019-09-18 15:19:30 +00:00
|
|
|
TenantUtil tenantUtil,
|
2019-09-20 15:08:45 +00:00
|
|
|
CoreBaseSettings coreBaseSettings,
|
2019-09-24 10:32:12 +00:00
|
|
|
IPSecurity.IPSecurity iPSecurity,
|
2019-11-08 12:21:51 +00:00
|
|
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
2020-01-17 13:58:26 +00:00
|
|
|
SettingsManager settingsManager,
|
2020-09-29 08:57:37 +00:00
|
|
|
UserFormatter userFormatter)
|
2019-08-01 08:47:15 +00:00
|
|
|
{
|
|
|
|
StudioNotifyService = studioNotifyService;
|
2019-09-09 12:56:33 +00:00
|
|
|
UserManager = userManager;
|
|
|
|
SecurityContext = securityContext;
|
2019-09-13 11:18:27 +00:00
|
|
|
MessageService = messageService;
|
|
|
|
CustomNamingPeople = customNamingPeople;
|
2019-09-17 12:42:32 +00:00
|
|
|
TenantUtil = tenantUtil;
|
2019-09-18 15:19:30 +00:00
|
|
|
CoreBaseSettings = coreBaseSettings;
|
2019-09-20 15:08:45 +00:00
|
|
|
IPSecurity = iPSecurity;
|
2019-11-08 12:21:51 +00:00
|
|
|
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
|
|
|
SettingsManager = settingsManager;
|
2020-01-17 13:58:26 +00:00
|
|
|
UserFormatter = userFormatter;
|
2019-08-01 08:47:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
private bool TestUniqueUserName(string uniqueName)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrEmpty(uniqueName))
|
2019-06-14 16:14:24 +00:00
|
|
|
return false;
|
2019-09-12 11:34:58 +00:00
|
|
|
return Equals(UserManager.GetUserByUserName(uniqueName), Constants.LostUser);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
private string MakeUniqueName(UserInfo userInfo)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(userInfo.Email))
|
|
|
|
throw new ArgumentException(Resource.ErrorEmailEmpty, "userInfo");
|
|
|
|
|
|
|
|
var uniqueName = new MailAddress(userInfo.Email).User;
|
|
|
|
var startUniqueName = uniqueName;
|
|
|
|
var i = 0;
|
2019-09-12 11:34:58 +00:00
|
|
|
while (!TestUniqueUserName(uniqueName))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
uniqueName = string.Format("{0}{1}", startUniqueName, (++i).ToString(CultureInfo.InvariantCulture));
|
|
|
|
}
|
|
|
|
return uniqueName;
|
|
|
|
}
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
public bool CheckUniqueEmail(Guid userId, string email)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
var foundUser = UserManager.GetUserByEmail(email);
|
2019-06-14 16:14:24 +00:00
|
|
|
return Equals(foundUser, Constants.LostUser) || foundUser.ID == userId;
|
|
|
|
}
|
|
|
|
|
2020-09-17 12:04:28 +00:00
|
|
|
public UserInfo AddUser(UserInfo userInfo, string passwordHash, bool afterInvite = false, bool notify = true, bool isVisitor = false, bool fromInviteLink = false, bool makeUniqueName = true)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
if (userInfo == null) throw new ArgumentNullException("userInfo");
|
|
|
|
|
|
|
|
if (!UserFormatter.IsValidUserName(userInfo.FirstName, userInfo.LastName))
|
|
|
|
throw new Exception(Resource.ErrorIncorrectUserName);
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
if (!CheckUniqueEmail(userInfo.ID, userInfo.Email))
|
2019-06-14 16:14:24 +00:00
|
|
|
throw new Exception(CustomNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
|
|
|
|
if (makeUniqueName)
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
userInfo.UserName = MakeUniqueName(userInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
if (!userInfo.WorkFromDate.HasValue)
|
|
|
|
{
|
|
|
|
userInfo.WorkFromDate = TenantUtil.DateTimeNow();
|
|
|
|
}
|
|
|
|
|
2019-09-18 15:19:30 +00:00
|
|
|
if (!CoreBaseSettings.Personal && !fromInviteLink)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
userInfo.ActivationStatus = !afterInvite ? EmployeeActivationStatus.Pending : EmployeeActivationStatus.Activated;
|
|
|
|
}
|
|
|
|
|
2020-10-12 13:52:31 +00:00
|
|
|
var newUserInfo = UserManager.SaveUserInfo(userInfo);
|
2020-09-17 12:04:28 +00:00
|
|
|
SecurityContext.SetUserPasswordHash(newUserInfo.ID, passwordHash);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2019-09-18 15:19:30 +00:00
|
|
|
if (CoreBaseSettings.Personal)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-09-18 12:14:15 +00:00
|
|
|
StudioNotifyService.SendUserWelcomePersonal(newUserInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
return newUserInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((newUserInfo.Status & EmployeeStatus.Active) == EmployeeStatus.Active && notify)
|
|
|
|
{
|
|
|
|
//NOTE: Notify user only if it's active
|
|
|
|
if (afterInvite)
|
|
|
|
{
|
|
|
|
if (isVisitor)
|
|
|
|
{
|
2019-08-30 12:40:57 +00:00
|
|
|
StudioNotifyService.GuestInfoAddedAfterInvite(newUserInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-20 15:53:27 +00:00
|
|
|
StudioNotifyService.UserInfoAddedAfterInvite(newUserInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fromInviteLink)
|
|
|
|
{
|
2019-09-17 12:42:32 +00:00
|
|
|
StudioNotifyService.SendEmailActivationInstructions(newUserInfo, newUserInfo.Email);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Send user invite
|
|
|
|
if (isVisitor)
|
|
|
|
{
|
2019-09-20 15:53:27 +00:00
|
|
|
StudioNotifyService.GuestInfoActivation(newUserInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-20 15:53:27 +00:00
|
|
|
StudioNotifyService.UserInfoActivation(newUserInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVisitor)
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
UserManager.AddUserIntoGroup(newUserInfo.ID, Constants.GroupVisitor.ID);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newUserInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Password
|
|
|
|
|
2019-09-13 11:18:27 +00:00
|
|
|
public void CheckPasswordPolicy(string password)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2019-08-15 13:16:39 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(password))
|
2019-06-14 16:14:24 +00:00
|
|
|
throw new Exception(Resource.ErrorPasswordEmpty);
|
|
|
|
|
2019-11-08 12:21:51 +00:00
|
|
|
var passwordSettingsObj = SettingsManager.Load<PasswordSettings>();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2019-09-23 12:20:08 +00:00
|
|
|
if (!CheckPasswordRegex(passwordSettingsObj, password))
|
2019-06-14 16:14:24 +00:00
|
|
|
throw new Exception(GenerateErrorMessage(passwordSettingsObj));
|
|
|
|
}
|
2020-09-18 07:59:23 +00:00
|
|
|
|
|
|
|
public string GetPasswordRegex(PasswordSettings passwordSettings)
|
2019-09-23 12:20:08 +00:00
|
|
|
{
|
|
|
|
var pwdBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
if (CoreBaseSettings.CustomMode)
|
|
|
|
{
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"^(?=.*[a-z]{0,})");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.Digits)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\d)");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.UpperCase)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[A-Z])");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.SpecSymbols)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[_\-.~!$^*()=|])");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"[0-9a-zA-Z_\-.~!$^*()=|]");
|
2019-09-23 12:20:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"^(?=.*\p{Ll}{0,})");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.Digits)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\d)");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.UpperCase)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*\p{Lu})");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
|
|
|
if (passwordSettings.SpecSymbols)
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"(?=.*[\W])");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@".");
|
2019-09-23 12:20:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 19:39:23 +00:00
|
|
|
pwdBuilder.Append(@"{");
|
|
|
|
pwdBuilder.Append(passwordSettings.MinLength);
|
|
|
|
pwdBuilder.Append(@",");
|
|
|
|
pwdBuilder.Append(PasswordSettings.MaxLength);
|
|
|
|
pwdBuilder.Append(@"}$");
|
2019-09-23 12:20:08 +00:00
|
|
|
|
2020-09-18 07:59:23 +00:00
|
|
|
return pwdBuilder.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckPasswordRegex(PasswordSettings passwordSettings, string password)
|
|
|
|
{
|
|
|
|
var passwordRegex = GetPasswordRegex(passwordSettings);
|
|
|
|
|
|
|
|
return new Regex(passwordRegex).IsMatch(password);
|
2019-09-23 12:20:08 +00:00
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2020-09-17 12:04:28 +00:00
|
|
|
public string SendUserPassword(string email)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
email = (email ?? "").Trim();
|
|
|
|
if (!email.TestEmailRegex()) throw new ArgumentNullException("email", Resource.ErrorNotCorrectEmail);
|
|
|
|
|
2019-09-20 15:53:27 +00:00
|
|
|
if (!IPSecurity.Verify())
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
throw new Exception(Resource.ErrorAccessRestricted);
|
|
|
|
}
|
|
|
|
|
2019-09-12 11:34:58 +00:00
|
|
|
var userInfo = UserManager.GetUserByEmail(email);
|
2019-09-09 12:56:33 +00:00
|
|
|
if (!UserManager.UserExists(userInfo) || string.IsNullOrEmpty(userInfo.Email))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
return string.Format(Resource.ErrorUserNotFoundByEmail, email);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
if (userInfo.Status == EmployeeStatus.Terminated)
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
return Resource.ErrorDisabledProfile;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
if (userInfo.IsLDAP())
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
return Resource.CouldNotRecoverPasswordForLdapUser;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
if (userInfo.IsSSO())
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
return Resource.CouldNotRecoverPasswordForSsoUser;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 15:53:27 +00:00
|
|
|
StudioNotifyService.UserPasswordChange(userInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2019-11-08 12:21:51 +00:00
|
|
|
var displayUserName = userInfo.DisplayUserName(false, DisplayUserSettingsHelper);
|
2019-09-13 11:18:27 +00:00
|
|
|
MessageService.Send(MessageAction.UserSentPasswordChangeInstructions, displayUserName);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2020-09-17 12:04:28 +00:00
|
|
|
return null;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 16:16:08 +00:00
|
|
|
public static string GeneratePassword()
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
return Guid.NewGuid().ToString();
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static readonly Random Rnd = new Random();
|
|
|
|
|
|
|
|
internal static string GeneratePassword(int minLength, int maxLength, string noise)
|
|
|
|
{
|
|
|
|
var length = Rnd.Next(minLength, maxLength + 1);
|
|
|
|
|
|
|
|
var pwd = string.Empty;
|
|
|
|
while (length-- > 0)
|
|
|
|
{
|
|
|
|
pwd += noise.Substring(Rnd.Next(noise.Length - 1), 1);
|
|
|
|
}
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static string GenerateErrorMessage(PasswordSettings passwordSettings)
|
|
|
|
{
|
|
|
|
var error = new StringBuilder();
|
|
|
|
|
2020-10-12 19:39:23 +00:00
|
|
|
error.AppendFormat("{0} ", Resource.ErrorPasswordMessage);
|
|
|
|
error.AppendFormat(Resource.ErrorPasswordLength, passwordSettings.MinLength, PasswordSettings.MaxLength);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.UpperCase)
|
2020-10-12 19:39:23 +00:00
|
|
|
error.AppendFormat(", {0}", Resource.ErrorPasswordNoUpperCase);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.Digits)
|
2020-10-12 19:39:23 +00:00
|
|
|
error.AppendFormat(", {0}", Resource.ErrorPasswordNoDigits);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.SpecSymbols)
|
2020-10-12 19:39:23 +00:00
|
|
|
error.AppendFormat(", {0}", Resource.ErrorPasswordNoSpecialSymbols);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
return error.ToString();
|
|
|
|
}
|
|
|
|
|
2019-11-08 12:21:51 +00:00
|
|
|
public string GetPasswordHelpMessage()
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
|
|
|
var info = new StringBuilder();
|
2019-11-08 12:21:51 +00:00
|
|
|
var passwordSettings = SettingsManager.Load<PasswordSettings>();
|
2020-10-12 19:39:23 +00:00
|
|
|
info.AppendFormat("{0} ", Resource.ErrorPasswordMessageStart);
|
|
|
|
info.AppendFormat(Resource.ErrorPasswordLength, passwordSettings.MinLength, PasswordSettings.MaxLength);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.UpperCase)
|
2020-10-12 19:39:23 +00:00
|
|
|
info.AppendFormat(", {0}", Resource.ErrorPasswordNoUpperCase);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.Digits)
|
2020-10-12 19:39:23 +00:00
|
|
|
info.AppendFormat(", {0}", Resource.ErrorPasswordNoDigits);
|
2019-06-14 16:14:24 +00:00
|
|
|
if (passwordSettings.SpecSymbols)
|
2020-10-12 19:39:23 +00:00
|
|
|
info.AppendFormat(", {0}", Resource.ErrorPasswordNoSpecialSymbols);
|
2019-06-14 16:14:24 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|