示例#1
0
        public FileResult VerifyKey(string key, int width = 0, int height = 0)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = "verifycode";
            }
            Entity.VerifyCode code = Config.UserConfig.getVerifyCode(key, false);
            if (code == null)
            {
                code = Config.UserConfig.setVerifyCode(key, Utils.random(4));
            }

            var          image  = UI.VerifyKey.getVerifyKey(code.Code, width, height);
            MemoryStream stream = new MemoryStream();

            image.Save(stream, ImageFormat.Png);
            image.Dispose();
            return(File(stream.ToArray(), "image/PNG"));
        }
示例#2
0
        /// <summary>
        /// 更新验证码
        /// </summary>
        /// <param name="info"></param>
        /// <param name="account">账号</param>
        /// <param name="code">验证码</param>
        /// <param name="minute">分钟</param>
        public static Entity.VerifyCode setVerifyCode(UserOnlineInfo info, string account, string code, int minute = 0)
        {
            var codeList = info.VerifyCode;

            Entity.VerifyCode codeInfo = codeList.Find(g => g.Account.Equals(account));
            if (codeInfo == null)
            {
                codeInfo         = new Entity.VerifyCode();
                codeInfo.Account = account.ToLower();
                info.VerifyCode.Add(codeInfo);
            }
            codeInfo.Code = code.ToLower();
            if (minute > 0)
            {
                codeInfo.Deadline = Config.SiteConfig.getLocalTime().AddMinutes(minute);
            }
            else
            {
                codeInfo.Deadline = null;
            }

            return(codeInfo);
        }