Ejemplo n.º 1
0
        /// <summary>
        /// 管理员登录
        /// 创建  毛枫  2015-4-21
        /// 修改  毛枫  2015-7-31
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool AdminLoginIn(string username, string password)
        {
            bool result = false;

            try
            {
                T_ADMIN admin = new T_ADMIN();
                admin = IsLoginFromSql(username, password);
                if (admin != null)
                {
                    #region Cookie和Session的设置
                    //System.Web.HttpContext.Current.Session["A_ID"] = admin.ID;
                    //System.Web.HttpContext.Current.Session["A_Code"] = admin.A_CODE;
                    //System.Web.HttpContext.Current.Session["A_TrueName"] = admin.A_TRUE_NAME;
                    //System.Web.HttpContext.Current.Session["A_AdminName"] = admin.A_NAME;
                    //System.Web.HttpContext.Current.Session.Timeout = 10800;
                    WebHelperUtil.SessionAdd("A_ID", admin.ID.ToString(), 60);
                    WebHelperUtil.SessionAdd("A_Code", admin.A_CODE, 60);
                    WebHelperUtil.SessionAdd("A_TrueName", admin.A_TRUE_NAME, 60);
                    WebHelperUtil.SessionAdd("A_AdminName", admin.A_NAME, 60);
                    ////生成用户模型
                    //System.Web.HttpContext.Current.Session["A_AdminUser"] = new AdminUserModel()
                    //{
                    //    A_ID = admin.ID,
                    //    A_CODE = admin.A_CODE,
                    //    A_NAME = admin.A_NAME,
                    //    A_CHINESE_NAME = admin.A_TRUE_NAME,
                    //};
                    string userModle = new AdminUserModel()
                    {
                        A_ID           = admin.ID,
                        A_CODE         = admin.A_CODE,
                        A_NAME         = admin.A_NAME,
                        A_CHINESE_NAME = admin.A_TRUE_NAME,
                    }.toJson();
                    //加密处理
                    userModle = EncryptUtil.Base64Encode(userModle);
                    WebHelperUtil.SetCookie("A_AdminUser", userModle, ExpiresDayCookiesSession);

                    //生成验证字符串cookie
                    string authStr = admin.ID + "^" + username.ToLower() + "^" + DateTime.Now.AddHours(2);
                    authStr = EncryptUtil.DESEncryptString(authStr);

                    //添加Cookie
                    WebHelperUtil.SetCookie("AdminToken", EncryptUtil.MD5(admin.ID.ToString(), 16), ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminAuth", authStr, ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminLastLogTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), ExpiresDayCookiesSession);
                    WebHelperUtil.SetCookie("AdminUserLogin", "login", ExpiresDayCookiesSession);
                    #endregion

                    LoginCommon.InsertAdminLoginLog(admin);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成LoginToken
        /// </summary>
        /// <returns></returns>
        public static string CreateLoginToken()
        {
            string startToken = System.Guid.NewGuid().ToString();

            return(EncryptUtil.Base64Encode(startToken));
        }