Beispiel #1
0
        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <returns></returns>
        public ActionResult ValidateCodeImg()
        {
            var Code = ValidateCodeHelper.GetRandomCode(7);

            ValidateCodeHelper.SetCodeString(Code);
            return(File(ValidateCodeHelper.GetVerifyCodeImg(Code), "image/Jpeg"));
        }
Beispiel #2
0
        public ActionResult GenerateValidCode()
        {
            var helper = new ValidateCodeHelper();
            var data   = helper.CreateValidateCode();

            return(File(data, "image/gif"));
        }
Beispiel #3
0
        public FileContentResult GetValidateCode()
        {
            ValidateCodeHelper vc = new ValidateCodeHelper();
            string             strValidateCode = vc.CreateValidateCode(4);

            Session["ValidateCode"] = strValidateCode;
            return(File(vc.CreateValidateGraphic(strValidateCode), "image/jpeg"));
        }
        public IActionResult GetValidateCode()
        {
            var vc = ValidateCodeHelper.GetValidateCode();

            HttpContext.Session.SetString("validateCode", vc.ValidateNum.ToLower());
            byte[] bs = vc.ImgStream;
            return(File(bs, @"image/Png"));
        }
Beispiel #5
0
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetValidateCode()
        {
            string code = RandomHelper.GetRandom(4);

            Session["ValidateCode"] = code;
            byte[] bytes = ValidateCodeHelper.CreateValidateGraphic(code);
            return(File(bytes, @"image/jpeg"));
        }
        public ActionResult GetVerifyCode()
        {
            string code = string.Empty;

            byte[] bytes = ValidateCodeHelper.CreateValidateGraphic(out code, 5, 120, 40, 20);
            Session["ValidateCode"] = code;
            return(File(bytes, @"image/jpeg"));
        }
Beispiel #7
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult yzm()
        {
            ValidateCodeHelper vch  = new ValidateCodeHelper();
            string             code = vch.GetRandomNumberString(4);

            Tools.WriteCookie("loginCode", code, 2);
            return(File(vch.CreateImage(code), "image/jpeg"));
        }
        public FileResult ValidateCode()
        {
            ValidateCodeHelper vCode = new ValidateCodeHelper();
            string             code  = vCode.CreateValidateCode(5);

            TempData[VALIDATECODE] = code;
            byte[] bytes = vCode.CreateValidateGraphic(code);
            return(File(bytes, @"image/jpeg"));
        }
Beispiel #9
0
        public FileResult ValidateCode()
        {
            ValidateCodeHelper validateCode = new ValidateCodeHelper();
            string             code         = validateCode.GetRandomNumberString(4);

            TempData[VALIDATECODE] = code;
            byte[] bytes = validateCode.CreateImage(code);
            return(File(bytes, @"image/jpeg"));
        }
Beispiel #10
0
        public void RegisterTest()
        {
            var Code = ValidateCodeHelper.GetRandomCode(7);

            ValidateCodeHelper.SetCodeString(Code);
            Assert.IsTrue(DefaultService.Register(new ResultModel(), new Model.RegisterModel {
                Password = "******", RePassword = "******", Telephone = "123456", UserName = "******", VerisonCode = Code
            }));
        }
        public ActionResult GetValidateCode()
        {
            ValidateCodeHelper codeHelper = new ValidateCodeHelper();
            string             strCode    = codeHelper.CreateValidateCode(5);

            Session[Sessionvalues.LoginValideCode] = strCode;
            byte[] data = codeHelper.CreateValidateGraphic(strCode);
            return(File(data, "image/jpeg"));
        }
Beispiel #12
0
        /// <summary>
        /// 图形验证码
        /// </summary>
        /// <returns></returns>
        public IActionResult ValidateCode()
        {
            string code = "";

            System.IO.MemoryStream ms = ValidateCodeHelper.CreateValidateCode(out code);
            Utility.SetSession("LoginValidateCode", code);
            Response.Body.Dispose();
            return(File(ms.ToArray(), @"image/png"));
        }
        public ActionResult GetValidateCode()
        {
            var    vCode = new ValidateCodeHelper();
            string code  = vCode.CreateValidateCode(4);

            Session["ValidateCode"] = code;
            byte[] bytes = vCode.CreateValidateGraphic(code);
            return(File(bytes, @"image/jpeg"));
        }
Beispiel #14
0
        public ActionResult GetValidateCode()
        {
            //创建验证码类的对象
            ValidateCodeHelper code    = new ValidateCodeHelper();
            string             strCode = code.CreateValidateCode(4);//生成验证码的长度

            Session["validateCode"] = strCode;
            byte[] buffer = code.CreateValidateGraphic(strCode);
            return(File(buffer, "image/jpeg"));
        }
Beispiel #15
0
        public byte[] GetVcode()
        {
            string strCode = ValidateCodeHelper.CreateValidateCode(4);

            //验证码放到Session里面去
            SessionHelper.Session[APPKeys.Vercode] = strCode;

            byte[] imgBytes = ValidateCodeHelper.CreateValidateGraphic(strCode);
            return(imgBytes);
        }
        public IActionResult GetValidateCode()
        {
            string validateString = ValidateCodeHelper.CreateVaildateString(4);

            byte[] buffer = ValidateCodeHelper.CreateValidateCode(validateString);
            string ip     = HttpContext.Connection.RemoteIpAddress.ToString();

            MemoryCacheHelper.SetCache(ip, validateString);
            return(File(buffer, @"image/png"));
        }
        public ActionResult VCode()
        {
            //引用的都是程序集。需要生成后才会有效果的。
            ValidateCodeHelper vCode = new ValidateCodeHelper();
            string             code  = vCode.CreateValidateCodeContainsLetter(4);

            Session["ValidateCode"] = code;
            byte[] bytes = vCode.CreateValidateGraphic(code);
            return(File(bytes, @"image/jpeg"));
        }
Beispiel #18
0
        // GET: ValidateCode
        public ActionResult Index()
        {
            int    width    = 120;
            int    height   = 40;
            int    fontsize = 18;
            string code     = string.Empty;

            byte[] bytes = ValidateCodeHelper.CreateValidateGraphic(out code, 4, width, height, fontsize);
            Session["VCode"] = code;
            return(File(bytes, @"image/jpeg"));
        }
        public ActionResult Index(string path, int width, int height)
        {
            var code = ValidateCodeHelper.GetValidateCode(4);

            Session["vcode_" + path] = code.ToLower();
            var image  = ValidateCodeHelper.CreateValidateImage(code);
            var stream = new MemoryStream();

            image.Save(stream, ImageFormat.Jpeg);
            image.Dispose();
            stream.Position = 0;
            return(File(stream, "image/jpeg", "verifyCode.jpg"));
        }
Beispiel #20
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var    valid = new ValidateCodeHelper();
         string code  = valid.CreateValidateCode(5);
         Session["validCode"] = code;
         var ImgCode = valid.CreateValidateGraphic(code);
         Response.ClearContent();
         Response.ContentType = "image/gif";
         Response.BinaryWrite(ImgCode);
     }
 }
Beispiel #21
0
        /// <summary>
        /// 图片验证码
        /// </summary>
        public ActionResult Validate()
        {
            Bitmap     bmp  = new Bitmap(80, 40);
            Graphics   g    = Graphics.FromImage(bmp);
            SolidBrush sb   = new SolidBrush(ValidateCodeHelper.GetColor());
            var        code = ValidateCodeHelper.BuildCode(4);

            CookieHelper.SetCookie("Validate", code, DateTime.Now.AddMinutes(5));
            g.DrawString(code, new Font("宋体", 20), sb, 0, 0);
            MemoryStream ms = new MemoryStream();

            bmp.Save(ms, ImageFormat.Png);
            return(File(ms.GetBuffer(), "application/x-png"));
        }
Beispiel #22
0
        public void ProcessRequest(HttpContext context)
        {
            var    vCode = new ValidateCodeHelper();
            string code  = vCode.CreateValidateCode(5);

            context.Session["ValidateCode"] = code;
            byte[]       bytes  = vCode.CreateValidateGraphic(code);
            MemoryStream ms     = new MemoryStream(bytes);
            Bitmap       bitmap = new Bitmap(ms);

            bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            context.Response.ContentType = "image/jpg";
            context.Response.End();
        }
Beispiel #23
0
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="type">1-系统级验证码 2-手机短信验证码 3-邮箱验证码</param>
        /// <returns></returns>
        private string GetSystemVerificationCode(string type)
        {
            string code = String.Empty;

            switch (type)
            {
            case "1":
                code = ValidateCodeHelper.GetRandLetterAndNumber(4, true);
                break;

            case "2":
                break;

            case "3":
                break;
            }
            return(code);
        }
        public AccountController(
            IEventService events,
            IIdentityServerInteractionService interaction,
            ValidateCodeHelper validateCodeHelper,
            AccountAppService accountAppService,
            IAbpSession abpSession,
            JwtTokenHandler jwtTokenHandler)
        {
            _Events = events;

            _Interaction = interaction;

            _ValidateCodeHelper = validateCodeHelper;

            _AccountAppService = accountAppService;

            _AbpSession = abpSession;

            _JwtTokenHandler = jwtTokenHandler;
        }
Beispiel #25
0
        public JsonResult CreateValidateCode()
        {
            //首先实例化验证码的类
            ValidateCodeHelper validateCode = new ValidateCodeHelper();
            //生成验证码指定的长度
            string code = validateCode.GetRandomString(4);
            //创建验证码的图片
            var base64Str = validateCode.CreateImage(code);
            var token     = Guid.NewGuid().ToString("N");

            using (RedisClient redisClient = RedisHelper.CreateClient())
            {
                redisClient.Set(token, code, TimeSpan.FromMinutes(5));
            }
            return(Json(new
            {
                base64Str,
                token
            }));
        }
Beispiel #26
0
        public static bool Register(ResultModel result, RegisterModel Model)
        {
            #region 表单验证
            ValidationContext       context = new ValidationContext(Model, null, null); ///创建验证实体
            List <ValidationResult> results = new List <ValidationResult>();            ///返回的ErrorMsgList
            var valid = Validator.TryValidateObject(Model, context, results, true);     ///执行验证
            if (!valid)
            {
                result.ErrorCode = -1;
                result.ErrorMsg  = $"注册失败 {results.FirstOrDefault()?.ErrorMessage}";
                return(false);
            }
            if (ValidateCodeHelper.CurrentCodeString != Model.VerisonCode.ToLower())
            {
                result.ErrorCode = -1;
                result.ErrorMsg  = $"注册失败 验证码错误";
                return(false);
            }
            #endregion

            ValidateCodeHelper.DeleteCodeString();//清除验证码

            #region 注册方法
            var UserOID   = Guid.NewGuid().ToString();
            var UserModel = new Data_User()
            {
                OID        = UserOID,
                Name       = Model.UserName,
                UserName   = Model.UserName,
                Password   = EncryptionHelper.HMACSMD5Encrypt(Model.Password, UserOID, Encoding.ASCII),
                Telephone  = Model.Telephone,
                IsDeleted  = false,
                IsLocked   = false,
                CreateTime = DateTime.Now
            };
            return(UserModel.Add());

            #endregion
        }
Beispiel #27
0
        public ActionResult Login(string name, string password, string validateCode = null)
        {
            //是否是安全IP地址
            var  currentIp = HttpContext.Connection.RemoteIpAddress.ToString();
            bool isSafeIp  = _projectSetting.Value.SafeIPAddress.Split(",").Any(c => c == currentIp);

            if (!isSafeIp)
            {
                if (string.IsNullOrEmpty(validateCode))
                {
                    return(ErrorJsonResult("请输入验证码"));
                }
                string code = HttpContext.Session.GetString("validateCode");
                if (code != validateCode.ToLower())
                {
                    return(ErrorJsonResult("验证码错误"));
                }
                //更新验证码
                HttpContext.Session.SetString("validateCode", ValidateCodeHelper.GetValidateCode().ValidateNum.ToLower());
            }
            var sr = _accountService.Login(name, password);

            if (!sr.IsSucceed)
            {
                return(ErrorJsonResult(sr.Message));
            }
            string cookieKey = _projectSetting.Value.CookieKey;
            //每一个登录用户生成不同的cookie
            string cookieValue = BitConverter.ToInt64(Guid.NewGuid().ToByteArray()).ToString();

            //写入cookie
            HttpContext.Response.Cookies.Append(cookieKey, cookieValue, new CookieOptions
            {
                Expires  = DateTime.Now.AddMinutes(_projectSetting.Value.SessionTimeOut),
                HttpOnly = true
            });
            //当前登录用户
            var currentSysUser = new CurrentSysUser()
            {
                UserID    = sr.Data.UserID,
                LoginName = sr.Data.LoginName,
                UserName  = sr.Data.UserName
            };
            var menuList = _accountService.GetMenuList(currentSysUser.UserID).Data;

            currentSysUser.MenuList = menuList.Select(s => new CurrentSysUserMenu()
            {
                ID       = s.MenuID,
                Name     = s.MenuName,
                URL      = s.URL,
                ParentID = s.ParentID,
                Icon     = s.Icon,
                Sort     = s.Sort
            }).ToList();
            //将用户权限以cookieValue为键写入cache
            string userCacheKey = GetCacheKey(cookieValue);

            //滑动方式添加缓存
            _cacheManager.Add(userCacheKey, currentSysUser, new TimeSpan(0, _projectSetting.Value.SessionTimeOut, 0), true);

            return(SuccessJsonResult());
        }
        public FileResult getcodeimage()
        {
            var bytes = ValidateCodeHelper.CreateValidateGraphic("4506");

            return(new FileContentResult(bytes, @"image/jpeg"));
        }
Beispiel #29
0
        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            IHttpContextAccessor httpContextAccessor = IocManager.Instance.Resolve <IHttpContextAccessor>();
            string             recvValidateCode      = httpContextAccessor.HttpContext.Request.Form["VaildCode"];
            ValidateCodeHelper validateCodeHelper    = IocManager.Instance.Resolve <ValidateCodeHelper>();
            string             validateCode          = validateCodeHelper.GetValidateCode();

            if (!string.Equals(validateCode, recvValidateCode, StringComparison.OrdinalIgnoreCase))
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "验证码错误");
                return;
            }
            AccountAppService accountAppService = IocManager.Instance.Resolve <AccountAppService>();

            IAbpSession abpSession = IocManager.Instance.Resolve <IAbpSession>();

            LoginInput input = new LoginInput();

            input.Username = context.UserName;
            input.Password = context.Password;
            input.TenantId = abpSession.TenantId;
            var output = await accountAppService.Login(input);

            if (!output.IsSuccess())
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, output.ErrorMessage);
                return;
            }
            var loginResult = output.AbpLoginResult;

            switch (loginResult.Result)
            {
            case AbpLoginResultType.Success:
                IdentityUser user = loginResult.User;
                context.Result = new GrantValidationResult(
                    subject: context.UserName,
                    authenticationMethod: "custom",
                    claims: new Claim[]
                {
                    new Claim("Id", user.Id.ToString()),
                    new Claim("UserName", user.UserName),
                    new Claim("EmailAddress", user.EmailAddress),
                    new Claim("Name", user.Name),
                }
                    );
                break;

            case AbpLoginResultType.InvalidUserNameOrEmailAddress:
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "不存在的用户名");
                break;

            case AbpLoginResultType.InvalidPassword:
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "密码错误");
                break;

            default:
                //验证失败
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "身份验证失败");
                break;
            }
        }