Example #1
0
        public static void Verify(FixValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string hashedCode, string toCheckCode, bool needDecrypt = true)
        {
            var errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int errorCount    = CheckErrorCount(verifier, errorCountKey);

            bool result = true;

            if (needDecrypt)
            {
                try
                {
                    toCheckCode = AES128.Decrypt(toCheckCode, AES128.DefaultKey);
                }
                catch
                {
                    result = false;
                }
            }

            result = result && verifier.Verify(plateForm, uniqueKey, hashedCode, toCheckCode);
            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
Example #2
0
        public static void Verify(ComputedValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string secretKey, string code, bool codeCanVerifyAgain = false)
        {
            var errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int errorCount    = CheckErrorCount(verifier, errorCountKey);

            if (!CheckCodeValid(verifier, plateForm, uniqueKey, code))
            {
                verifier.VerifyInvalidCode();
            }

            var result = verifier.Verify(secretKey, code);

            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
                if (!codeCanVerifyAgain)
                {
                    InvalidateCode(verifier, plateForm, uniqueKey, code);
                }
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
Example #3
0
        public static void SetModel <T>(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey, T model) where T : IVerified
        {
            string modelKey = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            model.ExpireTime = DateTime.UtcNow.AddMinutes(Constant.VERIFICATION_CACHE_TIME).ToUnixTime();
            RedisHelper.Set(RedisDBIndex, modelKey, model, TimeSpan.FromMinutes(Constant.TEMPTOKEN_EXPIRED_TIME));
        }
Example #4
0
 public ServiceResult <int> CurrentRank(SystemPlatform im)
 {
     return(new ServiceResult <int>()
     {
         Data = new InviteComponent().GetCurrentRank(im, this.GetUser())
     });
 }
Example #5
0
 public override bool Verify(SystemPlatform plateForm, string uniqueKey, string oldCode, string toCheckCode)
 {
     if (string.IsNullOrEmpty(toCheckCode))
     {
         return(false);
     }
     return(toCheckCode.Trim().Equals(oldCode.Trim(), System.StringComparison.CurrentCultureIgnoreCase));
 }
Example #6
0
        public int GetCurrentRank(SystemPlatform platform, UserAccount account)
        {
            var totalProfitAmount = new ProfitDetailDAC().GetUserBonusTotalAmount(account, (int)platform);

            if (totalProfitAmount == 0m)
            {
                return(-1);
            }
            return(new InviteRecordDAC().GetUserRanking(account.Id, (int)platform));
        }
Example #7
0
        /// <summary>
        /// 生成有规则的二维码字符串
        /// </summary>
        /// <param name="plateform">系统</param>
        /// <param name="business">业务</param>
        /// <param name="code">信息数据</param>
        /// <returns>二维码字符串</returns>
        public static string Generate(SystemPlatform plateform, QRCodeEnum business, string code)
        {
            if (!Enum.IsDefined(typeof(SystemPlatform), plateform) || !Enum.IsDefined(typeof(QRCodeEnum), business))
            {
                throw new ArgumentException();
            }

            string platformStr = ((int)plateform).ToString();
            string actionStr   = ((int)business).ToString();

            return($"{platformStr}-{actionStr}-{code}");
        }
Example #8
0
        public Dictionary <string, string> GetRegisterModel(SystemPlatform platform, string uniqueKey, bool deleteCode)
        {
            var extensionKey   = GetExtensionKey(platform, uniqueKey);
            var cacheExtension = RedisHelper.Get <Dictionary <string, string> >(Constant.REDIS_SMS_DBINDEX, extensionKey);

            if (deleteCode)
            {
                RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, extensionKey);
            }

            return(cacheExtension);
        }
Example #9
0
        public override bool Verify(SystemPlatform plateForm, string uniqueKey, string code)
        {
            var codeKey   = GetCodeKey(plateForm, uniqueKey);
            var codeModel = RedisHelper.Get <RandomCodeModel>(Constant.REDIS_SMS_DBINDEX, codeKey);

            if (codeModel == null)
            {
                return(false);
            }
            if (codeModel.ExpireTime <= DateTime.UtcNow.ToUnixTime())
            {
                CodeExpried();
            }
            return(codeModel.Code != null && code == codeModel.Code);
        }
Example #10
0
        public override string SendCode(SystemPlatform plateForm, string uniqueKey, string targetEmail, string subject)
        {
            var    isTestSMS = System.Configuration.ConfigurationManager.AppSettings["Test_Email"] == "1";
            var    code      = isTestSMS ? "123456" : new Random().Next(0, 1000000).ToString("000000");
            string merchant  = "";

            if (plateForm == SystemPlatform.FiiiPay)
            {
                merchant = "FiiiPay";
            }
            else if (plateForm == SystemPlatform.FiiiPOS)
            {
                merchant = "FiiiPOS";
            }
            new EmailAgent().Send(targetEmail, subject, string.Format(GeneralResources.EmailVerfiyMessage, code, Constant.EMAIL_EXPIRED_TIME), 5, merchant);
            return(code);
        }
Example #11
0
        public static void Verify <T>(CustomVerifier verifier, SystemPlatform plateForm, string uniqueKey, Func <T, bool> VerifyFunction) where T : IVerified
        {
            var    errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int    errorCount    = CheckErrorCount(verifier, errorCountKey);
            string modelKey      = verifier.GetVerifyModelKey(plateForm, uniqueKey);

            var model = RedisHelper.Get <T>(RedisDBIndex, modelKey);

            if (model != null && model.ExpireTime <= DateTime.UtcNow.ToUnixTime())
            {
                verifier.CodeExpried();
            }

            bool result = true;

            try
            {
                result = VerifyFunction.Invoke(model);
            }
            catch (Framework.Exceptions.CommonException ce)
            {
                result = false;
                IncreaseErrorCount(verifier, errorCountKey, ce);
            }
            catch (Exception ex)
            {
                result = false;
                IncreaseErrorCount(verifier, errorCountKey);
            }

            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
                InvalidateCode(verifier, plateForm, uniqueKey);
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
Example #12
0
        public static void SendCode(RandomValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string targetCellphone, string message = null)
        {
            var errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);

            CheckErrorCount(verifier, errorCountKey);

            var code = verifier.SendCode(plateForm, uniqueKey, targetCellphone, message);

            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            var model = new RandomCodeModel
            {
                Code       = code,
                ExpireTime = DateTime.UtcNow.AddMinutes(verifier.GetExpireTime()).ToUnixTime()
            };
            string codeKey = verifier.GetCodeKey(plateForm, uniqueKey);

            RedisHelper.Set(RedisDBIndex, codeKey, model, TimeSpan.FromMinutes(Constant.SMS_CACHE_TIME));
        }
Example #13
0
        public static void Verify(RandomValueVerifier verifier, SystemPlatform plateForm, string uniqueKey, string code, bool codeCanVerifyAgain = false)
        {
            var  errorCountKey = verifier.GetErrorCountKey(plateForm, uniqueKey);
            int  errorCount    = CheckErrorCount(verifier, errorCountKey);
            var  codeKey       = verifier.GetCodeKey(plateForm, uniqueKey);
            var  codeModel     = RedisHelper.Get <RandomCodeModel>(Constant.REDIS_SMS_DBINDEX, codeKey);
            bool result        = verifier.Verify(plateForm, uniqueKey, code);

            if (result)
            {
                if (errorCount > 0)
                {
                    DeleteErrorCount(errorCountKey);
                }
                if (!codeCanVerifyAgain)
                {
                    InvalidateCode(verifier, plateForm, uniqueKey);
                }
            }
            else
            {
                IncreaseErrorCount(verifier, errorCountKey);
            }
        }
Example #14
0
        /// <summary>
        /// 获取系统登录信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="username"></param>
        /// <param name="fullname"></param>
        /// <returns></returns>
        public string GetAppParameters(HttpContext context, string username,
                                       string fullname)//string roleId, string userid
        {
            #region
            SystemPlatform platform = new SystemPlatform(context);
            JsonHelper     jsonhlp  = new JsonHelper();

            jsonhlp.AddObjectToJson("contactus", platform.GetContactUs());
            jsonhlp.AddObjectToJson("developby", platform.GetDevelopBy());
            jsonhlp.AddObjectToJson("systemversion", "V " + Assembly.GetCallingAssembly().GetName().Version.ToString());
            jsonhlp.AddObjectToJson("serverIp", platform.GetServerIp());
            jsonhlp.AddObjectToJson("browserversion", platform.GetBrowserVersion());
            jsonhlp.AddObjectToJson("browser", platform.GetBrowserName());
            jsonhlp.AddObjectToJson("osname", platform.GetClientOS());
            jsonhlp.AddObjectToJson("clientIp", platform.GetClientIp());
            jsonhlp.AddObjectToJson("logontime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            jsonhlp.AddObjectToJson("fullname", fullname);
            //jsonhlp.AddObjectToJson("rolename", rolename);
            jsonhlp.AddObjectToJson(ApplicationUserData.Username, username);

            return(jsonhlp.ToString());

            #endregion
        }
Example #15
0
 public SMSCodeComponent(SystemPlatform platform)
 {
     Platform = platform;
 }
Example #16
0
 public override bool Verify(SystemPlatform plateForm, string uniqueKey, string hashedCode, string toCheckCode)
 {
     //string _pin = AES128.Decrypt(toCheckCode, AES128.DefaultKey);
     return(PasswordHasher.VerifyHashedPassword(hashedCode, toCheckCode));
 }
Example #17
0
 public virtual string GetErrorCountKey(SystemPlatform plateForm, string uniqueKey)
 {
     return($"{plateForm}:{GetVerifyTypeName()}:ErrorCounts:{uniqueKey}");
 }
Example #18
0
 /// <summary>
 /// Google验证通过后,当前验证码在所有业务中无效
 /// </summary>
 /// <param name="plateForm"></param>
 /// <param name="subName"></param>
 /// <param name="business"></param>
 /// <param name="uniqueKey"></param>
 /// <param name="code"></param>
 /// <returns></returns>
 public override string GetBeUsedKey(SystemPlatform plateForm, string uniqueKey, string code)
 {
     return($"{plateForm}:GoogleVerifier:Beused:{uniqueKey}:{code}");
 }
 public abstract bool Verify(SystemPlatform plateForm, string uniqueKey, string code);
Example #20
0
        public void DeleteCacheModel(SystemPlatform platform, string uniqueKey)
        {
            var extensionKey = GetExtensionKey(platform, uniqueKey);

            RedisHelper.KeyDelete(Constant.REDIS_SMS_DBINDEX, extensionKey);
        }
Example #21
0
 public abstract bool Verify(SystemPlatform plateForm, string uniqueKey, string hashedCode, string toCheckCode);
Example #22
0
        public void CacheRegisterModel(SystemPlatform platform, string uniqueKey, object extension)
        {
            var extensionKey = GetExtensionKey(platform, uniqueKey);

            RedisHelper.Set(Constant.REDIS_SMS_DBINDEX, extensionKey, extension, TimeSpan.FromMinutes(Constant.TEMPTOKEN_EXPIRED_TIME));
        }
Example #23
0
        public override string SendCode(SystemPlatform plateForm, string uniqueKey, string targetCellphone, string message = null)
        {
            var isTestSMS       = System.Configuration.ConfigurationManager.AppSettings["Test_Sms"] == "1";
            var keyByCount      = $"{plateForm}:CellphoneVerifier:SendCount:{uniqueKey}";
            var keyTimeInterval = $"{plateForm}:CellphoneVerifier:SendInterval:{GetBussinessName()}:{uniqueKey}";

            var sentCode = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyTimeInterval);

            if (!string.IsNullOrEmpty(sentCode))
            {
                return(null);
            }

            var limit    = string.IsNullOrWhiteSpace(Constant.SEND_SMS_LIMIT) ? 20 : Convert.ToInt32(Constant.SEND_SMS_LIMIT);
            var countStr = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyByCount);

            int.TryParse(countStr, out int count);
            if (count >= limit)
            {
                throw new CommonException(ReasonCode.PHONECODE_SEND_TOOMANY_TIMES, GeneralResources.SMSLimit);
            }

            var dateNow           = DateTime.Now;
            var tomorrowStartTime = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day).AddDays(1);

            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyByCount, (count + 1).ToString(), tomorrowStartTime - dateNow);//一天内限制发送条数,每天重置

            //var keyByCode = base.GetCodeKey(plateForm, "CellphoneVerifier", business, uniqueKey);
            var code = string.Empty;

            //var codeInDb = RedisHelper.StringGet(Constant.REDIS_SMS_DBINDEX, keyByCode);
            //if (!string.IsNullOrEmpty(codeInDb))
            //{
            //    code = codeInDb;
            //}
            //else
            //{
            //    code = isTestSMS ? "123456" : new Random().Next(0, 1000000).ToString("000000");
            //}

            //暂定每次发送的验证码不同
            code = isTestSMS ? "123456" : new Random().Next(0, 1000000).ToString("000000");

            string template = string.Empty;

            switch (plateForm)
            {
            case SystemPlatform.FiiiPOS:
                template = GeneralResources.SMS_Template_POS;
                break;

            case SystemPlatform.FiiiPay:
            case SystemPlatform.FiiiShop:
                template = GeneralResources.SMS_Template_FiiiPay;
                break;
            }
            string msmStr = string.Format(template, code, Constant.SMS_EXPIRED_TIME);

            if (!isTestSMS)
            {
                new Data.Agents.SMSAgent().Send(targetCellphone, msmStr, 5);
            }

            Info($"SMSSend:PlateForm:{plateForm},Business:{GetBussinessName()},Cellphone:{targetCellphone},Content:{msmStr}");

            RedisHelper.StringSet(Constant.REDIS_SMS_DBINDEX, keyTimeInterval, code, new TimeSpan(0, 1, 0));
            return(code);
        }
 public virtual string GetCodeKey(SystemPlatform plateForm, string uniqueKey)
 {
     return($"{plateForm}:{GetBussinessName()}:{GetVerifyTypeName()}:Code:{uniqueKey}");
 }
Example #25
0
 public string GetErrorCountKey(SystemPlatform plateForm, string uniqueKey)
 {
     return($"{plateForm}:{BussniessName}:ErrorCounts:{uniqueKey}");
 }
 /// <summary>
 /// 生成用户可扫描的谷歌认证初始码
 /// </summary>
 /// <param name="platForm">issuser</param>
 /// <param name="accountTitleNoSpaces">帐户名</param>
 /// <param name="accountSecretKey">共享密钥</param>
 /// <returns>SetupCode object</returns>
 public SetupCode GenerateSetupCode(SystemPlatform platForm, string accountTitleNoSpaces, string accountSecretKey)
 {
     return(GenerateSetupCode(platForm.ToString(), accountTitleNoSpaces, accountSecretKey));
 }
Example #27
0
 public virtual string GetVerifyModelKey(SystemPlatform plateForm, string uniqueKey)
 {
     return($"{plateForm}:{BussniessName}:VerifyModel:{uniqueKey}");
 }
Example #28
0
 public virtual string GetBeUsedKey(SystemPlatform plateForm, string uniqueKey, string code)
 {
     return($"{plateForm}:{GetVerifyTypeName()}:Beused:{uniqueKey}:{code}");
 }
Example #29
0
 private string GetExtensionKey(SystemPlatform platform, string uniqueKey)
 {
     return($"{platform}:{GetBussinessName()}:Code:{uniqueKey}:Extension");
 }
 public abstract string SendCode(SystemPlatform plateForm, string uniqueKey, string target, string message);