예제 #1
0
        private bool CheckSafeKey(int second)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["aries_safekey"];

            if (cookie != null)
            {
                string value = EncrpytHelper.Decrypt(cookie.Value);
                if (value.StartsWith("aries:"))
                {
                    if (second == 0)
                    {
                        return(true);
                    }
                    int time;
                    if (int.TryParse(value.Split(':')[1], out time))
                    {
                        int result = int.Parse(DateTime.Now.ToString("HHmmss")) - time;
#if DEBUG
                        return(result > -1 && result < 120);//2分钟的调试时间
#else
                        return(result > -1 && result < second);
#endif
                    }
                }
            }
            return(false);
        }
예제 #2
0
        private static string GetTokenValue(int index)
        {
            string token = Token;

            if (!string.IsNullOrEmpty(token))
            {
                string text = EncrpytHelper.Decrypt(token);
                if (!string.IsNullOrEmpty(text))
                {
                    string[] items = text.Split(',');
                    if (items.Length > index)
                    {
                        return(items[index]);
                    }
                }
            }
            return(string.Empty);
        }
예제 #3
0
        public override void Get()
        {
            switch (TableName)
            {
            case "Sys_User":
                ObjName = "V_SYS_UserList";
                MDataRow row = GetOne();
                if (row != null)
                {
                    row.Set("Password", EncrpytHelper.Decrypt(row.Get <string>("Password")));
                    jsonResult = row.ToJson();
                }
                break;

            default:
                base.Get();
                break;
            }
        }
예제 #4
0
        private static Dictionary <string, string> pcTokenList = new Dictionary <string, string>();//loginID,token

        /// <summary>
        /// 获取授权Token(手机APP登陆调用此方法获取Token为登陆凭证)
        /// </summary>
        public static string GetAuthToken(string userName, string password, out string errMsg)
        {
            string token = string.Empty;

            errMsg = string.Empty;
            using (MAction action = new MAction(U_AriesEnum.Sys_User))
            {
                string where = string.Empty;
                if (action.DalType == DalType.Txt || action.DalType == DalType.Xml)
                {
                    where = string.Format("Status=1 and UserName='******'", userName);
                }
                else
                {
                    action.SetPara("UserName", userName, System.Data.DbType.String);
                    where = "Status=1 and (UserName=@UserName or Phone=@UserName or Email=@UserName)";
                }
                if (action.Fill(where))
                {
                    if (action.Get <DateTime>(Sys_User.PwdExpiredTime, DateTime.MaxValue) < DateTime.Now)
                    {
                        errMsg = LangConst.PasswordExpired;
                    }
                    else
                    {
                        string pwd = action.Get <string>(Sys_User.Password);
                        if (password == EncrpytHelper.Decrypt(pwd, false))
                        {
                            string userID = action.Get <string>(Sys_User.UserID);
                            userName = action.Get <string>(Sys_User.UserName);
                            string fullName = action.Get <string>(Sys_User.FullName, userName);
                            if (action.DalType == DalType.Txt || action.DalType == DalType.Xml)
                            {
                                action.Set(Sys_User.LoginCount, action.Get <int>(Sys_User.LoginCount, 0) + 1);
                            }
                            else
                            {
                                action.SetExpression("LoginCount=[#ISNULL](LoginCount,0)+1");
                            }
                            if (!pwd.EndsWith("=2") && EncrpytHelper.EncrpytKey != "")
                            {
                                action.Set(Sys_User.Password, EncrpytHelper.Encrypt(password));//重新加密密码
                            }
                            action.Set(Sys_User.LastLoginTime, DateTime.Now);
                            action.Set(Sys_User.LastLoginIP, HttpContext.Current.Request.UserHostAddress);
                            //action.SetPara("UserName", userName, System.Data.DbType.String);
                            action.Update(where);//更新信息。
                            //获取角色名称
                            string roleIDs = action.Get <string>(Sys_User.RoleIDs);
                            token = EncrpytHelper.Encrypt(DateTime.Now.Day + "," + userID + "," + userName + "," + fullName + "," + roleIDs);
                        }
                        else
                        {
                            errMsg = LangConst.PasswordError;
                        }
                    }
                }
                else
                {
                    errMsg = LangConst.UserNotExists;
                }
            }
            return(token);
        }