Exemplo n.º 1
0
        public ActionResult Auth(string userName, string password) {
            var wa = new WebAuthenticator();
            var result = wa.Authenticate(userName, password);
            var maxTry = 3;

            string salt;
            var pwd = WebHelper.EncryptPassword(password, out salt);

            if (!result){
                var userSvc = new UserAppService();
                var user = userSvc.GetUserByName(userName);

                if (user != null){
                    if (user.UserStateId == 3) return this.Json("BLOCKED");
                    this.Session["AccessTryCounter"] = user.TryAccessCount;
                    var counter = Convert.ToInt32(this.Session["AccessTryCounter"]);
                    this.Session["AccessTryCounter"] = counter + 1;
                    counter = Convert.ToInt32(this.Session["AccessTryCounter"]);
                    if (counter >= maxTry){
                        WebHelper.UpdateUserTryCounter(userName, counter);
                        WebHelper.UpdateUserState(userName, 3); //Block User 
                        new BuildRecord().Add(user, 2);
                        return this.Json("BLOCKED");
                    }

                    WebHelper.UpdateUserTryCounter(userName, counter);
                }
            } else{
                var userSvc = new UserAppService();
                var user = userSvc.GetUserByName(userName);
                if (user.UserStateId == 3) return this.Json("BLOCKED");
                WebHelper.UpdateUserTryCounter(userName, 0);
                this.Session["LastLoginDate"] = user.LastLoginDate;
                WebHelper.UpdateLastLoginDate(user.UserId);
                this.Session["AccessTryCounter"] = 0;
                new BuildRecord().Add(user, 1);
            }

            return this.Json(result ? "OK" : string.Empty);
        }
Exemplo n.º 2
0
        public ActionResult Auth(string userName, string password)
        {
            var wa = new WebAuthenticator();

            return Json(wa.Authenticate(userName, password) ? "OK" : string.Empty);
        }