Ejemplo n.º 1
0
        private void LoginNameLogin(System.Web.Http.Controllers.HttpActionContext actionContext, string userInfo)
        {
            var tokens    = userInfo.Split(':');
            var loginName = tokens[0].Trim();
            var password  = tokens[1].Trim();

            var obj = CacheHelper.GetCache("bu_" + loginName);

            if (obj != null)
            {
                var cacheUser     = (string)obj;
                var passArr       = cacheUser.Split(':');
                var calcuPassword = DEncrypt.CalculatePassword(password, passArr[0]);

                if (calcuPassword == passArr[1])
                {
                    IsAuthorized(actionContext);
                    return;
                }
                CacheHelper.RemoveAllCache("bu_" + loginName);
            }

            RunTecMs.BLL.FaFaApi.User bll = new RunTecMs.BLL.FaFaApi.User();
            var user = bll.GetLoginUser(loginName);

            if (user == null)
            {
                HandleUnauthorizedRequest(actionContext);
                return;
            }

            var calculatedPassword = DEncrypt.CalculatePassword(password, user.PwdSalt);

            if (calculatedPassword == user.Password)
            {
                IsAuthorized(actionContext);
                CacheHelper.SetCache("bu_" + loginName, user.PwdSalt + ":" + user.Password, TimeSpan.FromSeconds(20));
                user = null;
            }
            else
            {
                HandleUnauthorizedRequest(actionContext);
            }
        }