/// <summary>
        /// Encrypt Answer
        /// </summary>
        /// <param name="answer"></param>
        /// <returns></returns>
        // FIXED-FEB16 - Move "[^0-9a-z]+" to constant
        public string EncryptAnswer(string answer)
        {
            string encryptedString = string.Empty;

            if (answer != null)
            {
                string convertToLower = answer.ToLower();
                encryptedString = Regex.Replace(convertToLower, Constants.SpecialCharacterPatterne, string.Empty);
            }
            return(EncryptDecryptPassword.EncryptText(encryptedString));
        }
 /// <summary>
 /// Add question answer and password.
 /// </summary>
 /// <returns></returns>
 public int AddQuestionAnswerAndPassword(User user)
 {
     if (user != null)
     {
         string passwordSalt = GetPasswordSalt(user);
         string passwordHash = EncryptDecryptPassword.EncryptText(string.Format("{0}{1}", user.PasswordHash, passwordSalt));
         _cmd = _db.GetStoredProcCommand("AddQuestionAnswerAndPassword");
         _db.AddInParameter(_cmd, "@UserID", DbType.Int32, user.UserId);
         _db.AddInParameter(_cmd, "@PasswordHash", DbType.String, passwordHash);
         _db.AddInParameter(_cmd, "@PasswordSalt", DbType.String, passwordSalt);
         _db.AddInParameter(_cmd, "@SecuirtyQuestionAnswer", DbType.Xml, Serializer.ToXml(user.UserSecurityQuestion));
         _db.AddInParameter(_cmd, "@EmailType", DbType.Int32, user.EmailType);
         _db.AddInParameter(_cmd, "@UserName", DbType.String, user.RequestedUserName);
         return(Convert.ToInt32(_db.ExecuteScalar(_cmd)));
     }
     return(0);
 }
        /// <summary>
        /// IsEmail Notification Send
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsEmailNotificationSend(User user)
        {
            if (user != null)
            {
                string emailContent, emailSubject = string.Empty;
                string serverMapPath = user.EmailType == Convert.ToInt32(Enums.EmailType.AccountActivation)
                    ? Server.MapPath(Constants.MailMessageTemplate)
                    : Server.MapPath(Constants.PasswordResetTemplate);
                using (StreamReader reader = new StreamReader(serverMapPath))
                {
                    emailContent = reader.ReadToEnd();
                }
                switch ((Enums.EmailType)Convert.ToInt32(user.EmailType))
                {
                case Enums.EmailType.AccountActivation:
                    emailSubject = Constants.MailSubject;
                    emailContent = emailContent.Replace("##LINK", Constants.ActivationMailLink);
                    break;

                case Enums.EmailType.AccountReset:
                    emailSubject = Constants.MailSubjectAccountReset;
                    emailContent = emailContent.Replace("##LINK", Constants.ResetAccountMailLink);
                    break;

                case Enums.EmailType.ChangePassword:
                    emailSubject = Constants.MailSubjectChangePassword;
                    emailContent = emailContent.Replace("##LINK", Constants.ChangePasswordMailLink);
                    break;

                case Enums.EmailType.PasswordReset:
                    emailSubject = Constants.MailSubjectPasswordReset;
                    emailContent = emailContent.Replace("##LINK", Constants.ResetPasswordMailLink);
                    break;

                case Enums.EmailType.RecoverPassword:
                    emailSubject = Constants.MailSubjectRecoverPassword;
                    emailContent = emailContent.Replace("##LINK", Constants.RecoverPasswordMailLink);
                    break;
                }

                Uri    url        = System.Web.HttpContext.Current.Request.Url;
                string domainName = string.Format("{0}/{1}", url.GetLeftPart(UriPartial.Authority),
                                                  (url.Segments.Length >= 2) ? url.Segments[1] : String.Empty);

                //email token
                string emailLink = string.Format("{0}{1}{2}", domainName, Constants.EmailUrl,
                                                 Server.UrlEncode(EncryptDecryptPassword.EncryptText(user.UserGuid.ToString())));

                emailContent = emailContent.Replace("##DATA", user.EmailType == Convert.ToInt32(Enums.EmailType.AccountActivation) ?
                                                    Constants.ActivationMailBody : Constants.PasswordMailBody);

                // Change http to https in email link url for production not other environment
                string httpsEmailLink = emailLink;
                if (!Constants.HttpUrls.Contains(url.Host))
                {
                    httpsEmailLink = emailLink.Replace(Constants.Http, Constants.Https);
                }
                emailContent = emailContent.Replace("##GUID", httpsEmailLink);

                if (user.EmailType != Convert.ToInt32(Enums.EmailType.AccountActivation))
                {
                    emailContent = emailContent.Replace("##NAME", string.Format("{0} {1}", user.FirstName, user.LastName));
                }

                try
                {
                    SaveEmailLog(user);
                    Utilities.SendMail(emailSubject, emailContent, user.UserName);
                }
                catch (Exception ex)
                {
                    Log.LogError("Send Email Exeception", user.UserName, ex);
                }
            }
            return(true);
        }