コード例 #1
0
ファイル: SupportBiz.cs プロジェクト: 3guy/GameTrans
 public static bool CheckShortMessageCode(string username, string mobile, string mobileCode, CheckCodeType checkCodeType)
 {
     var code = new CheckCodeStream().Find(c => c.UserName == username && c.Mobile == mobile
      && c.Type == (int)checkCodeType);
     if (code == null || code.ExpireDate < DateTime.Now || code.Code != mobileCode)
     {
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: ExFile.cs プロジェクト: GlibWild/ExCollection
        public static string GetCheckCodeFromFile(this FileStream file, CheckCodeType codeType = CheckCodeType.MD5, string spliteChar = "")
        {
            string result = string.Empty;

            switch (codeType)
            {
            case CheckCodeType.MD5:
            {
                var md5   = new MD5CryptoServiceProvider();
                var bytes = md5.ComputeHash(file);
                file.Close();
                result = bytes.ToHexString(spliteChar);
            }
            break;

            case CheckCodeType.SHA1:
            {
                var sha1  = SHA1.Create();
                var bytes = sha1.ComputeHash(file);
                file.Close();
                result = bytes.ToHexString(spliteChar);
            }
            break;

            case CheckCodeType.SHA256:
            {
                var sha1  = SHA256.Create();
                var bytes = sha1.ComputeHash(file);
                file.Close();
                result = bytes.ToHexString(spliteChar);
            }
            break;

            case CheckCodeType.SHA384:
            {
                var sha1  = SHA384.Create();
                var bytes = sha1.ComputeHash(file);
                file.Close();
                result = bytes.ToHexString(spliteChar);
            }
            break;

            case CheckCodeType.SHA512:
            {
                var sha1  = SHA512.Create();
                var bytes = sha1.ComputeHash(file);
                file.Close();
                result = bytes.ToHexString(spliteChar);
            }
            break;
            }
            return(result);
        }
コード例 #3
0
ファイル: ExFile.cs プロジェクト: GlibWild/ExCollection
        public static string GetCheckCodeFromFile(this string filePath, CheckCodeType codeType, string spliteChar = "")
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(filePath))
            {
                if (File.Exists(filePath))
                {
                    using (FileStream fs = new FileStream(filePath, FileMode.Open))
                    {
                        result = fs.GetCheckCodeFromFile(codeType, spliteChar);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// 产生验证码,根据数据库s_constant设置的位数
        /// </summary>
        /// <param name="type">验证码类型:数字,字符,符合</param>
        /// <returns></returns>
        public string CreateCheckCode(CheckCodeType type, int length)
        {
            string checekCode = string.Empty;

            switch (type)
            {
            case CheckCodeType.NumberCheckCode:
                checekCode = GetSingleObj().CreateNumberCheckCode(length);
                break;

            case CheckCodeType.AbcCheckCode:
                checekCode = GetSingleObj().CreateAbcCheckCode(length);
                break;

            case CheckCodeType.MixCheckCode:
                checekCode = GetSingleObj().CreateMixCheckCode(length);
                break;
            }
            return(checekCode);
        }
コード例 #5
0
ファイル: SupportBiz.cs プロジェクト: 3guy/GameTrans
        private static CheckCodeStream GetCheckCode(string username,string phone, CheckCodeType checkCodeType, int codeLength = 6, bool isRefrash = true)
        {
            var code = new CheckCodeStream().Find(c => c.UserName == username
             && c.Type == (int)checkCodeType);
            if (!isRefrash)
            {
                return code;
            }

            var newcode = GetRandomCode(codeLength);

            if (code == null)
            {
                //第一次获取此类型验证码
                //添加此类型验证码
                code = new CheckCodeStream()
                {
                    Code = newcode,
                    ExpireDate = DateTime.Now.Add(new TimeSpan(0, 5, 0)),
                    RecordDate = DateTime.Now,
                    Type = checkCodeType,
                    UserName = username,
                    Mobile = phone
                }.PostAdd();
            }
            else
            {
                code.Code = newcode;
                code.ExpireDate = DateTime.Now.Add(new TimeSpan(0, 5, 0));
                code.RecordDate = DateTime.Now;
                code.Mobile = phone;
                code = code.PostModify();
                //覆盖之前验证码
            }
            return code;
        }
コード例 #6
0
ファイル: SupportBiz.cs プロジェクト: 3guy/GameTrans
 /// <summary>
 /// 发送手机验证码
 /// </summary>
 /// <param name="username"></param>
 /// <param name="mobile"></param>
 /// <returns>返回正确的验证码</returns>
 public static string SendShortMessageCode(string username, string mobile, CheckCodeType checkCodeType)
 {
     var entity = GetCheckCode(username, mobile, checkCodeType);
     string reason = string.Empty;
     switch(checkCodeType)
     {
         case CheckCodeType.RegisterShortMessageCode:
             reason = "注册新用户";
             break;
         case CheckCodeType.ResetPasswordShortMessageCode:
             reason = "找回密码";
             break;
         case CheckCodeType.SetMobileShortMessageCode:
             reason = "绑定手机";
             break;
         case CheckCodeType.ResetPhoneShortMessageCode:
             reason = "更改绑定手机号";
             break;
         case CheckCodeType.LoginAdminShortMessageCode:
             reason = "登陆后台";
             break;
     }
     WorkPool.Append<ValidateCodeMessageModel>(WorkType.shortmessage_for_validateCode,
                 new ValidateCodeMessageModel()
                 {
                     Code = entity.Code,
                     Reason = reason,
                     Recipient = mobile
                 });
     return entity.Code;
 }