예제 #1
0
        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";
            CookiesHelper.WriteCookie("abc", Utils.GetRandomChar(20), 10);
            //sessiong
            SessionHelper.WriteSession("bcd", Utils.GetRandomChar(20));
            HttpContext.Session.SetString("abc", "123456");

            return(View());
        }
예제 #2
0
        /// <summary>
        /// 设置管理员信息,写入Session 和Cookies
        /// </summary>
        /// <param name="adminName">管理员帐号</param>
        /// <param name="adminPwd">管理员密码,经过加密后的</param>
        /// <param name="adminID">管理员ID</param>
        /// <param name="isSupperAdmin">是否是超级管理员</param>
        /// <param name="adminPower">管理员管理权限</param>
        /// <param name="adminLogID">后台日志ID</param>
        /// <param name="adminSalt">加密盐</param>
        public static void SetAdminInfo(string adminName, string adminPwd, int adminID, int isSupperAdmin, string adminPower, string adminLogID, string adminSalt)
        {
            //写入 session
            SessionHelper.WriteSession(sessionAdminIDKey, adminID.ToString());
            SessionHelper.WriteSession(sessionAdminNameKey, adminName);
            SessionHelper.WriteSession(sessionAdminPowerKey, adminPower);
            SessionHelper.WriteSession(sessionIsSupperAdminKey, isSupperAdmin.ToString());
            SessionHelper.WriteSession(sessionAdminLogIDKey, adminLogID);

            //写入cookie
            CookiesHelper.WriteCookie(cookiesAdminIDKey, adminID.ToString(), 120);
            CookiesHelper.WriteCookie(cookiesAdminNameKey, adminName, 120);
            //2016-6-01 增加IP加密信息,防止cookies被盗用
            CookiesHelper.WriteCookie(cookiesAdminInfoKey, Utils.MD5(adminName + adminPwd + adminSalt + Utils.GetIP()), 120);
            CookiesHelper.WriteCookie(sessionAdminLogIDKey, adminLogID, 120);
        }
예제 #3
0
        /// <summary>
        /// 将用户信息写入Session 和Cookies 保存用户登录状态
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码(经过md5加密)</param>
        /// <param name="uid">用户ID</param>
        /// <param name="expiresMin">保存时间</param>
        /// <param name="logguid">日志guid</param>
        /// <param name="salt">盐</param>
        public static void SetUserInfo(string username, string password, int uid, int expiresMin, string salt, string logguid)
        {
            //写入 session
            SessionHelper.WriteSession(KEY_S_UserName, username);
            SessionHelper.WriteSession(KEY_S_Uid, uid);
            SessionHelper.WriteSession(KEY_C_LOGID, logguid);

            //写入cookie
            CookiesHelper.WriteCookie(KEY_C_UserName, username, expiresMin);
            CookiesHelper.WriteCookie(KEY_C_Uid, uid.ToString(), expiresMin);
            CookiesHelper.WriteCookie(KEY_C_UserInfo, Utils.MD5(username + password), expiresMin);

            //2016-6-01 增加IP加密信息,防止cookies被盗用
            CookiesHelper.WriteCookie(KEY_C_UserInfo, Utils.MD5(username + password + salt), expiresMin);
            CookiesHelper.WriteCookie(KEY_C_LOGID, logguid, 60 * 2);
        }
예제 #4
0
파일: CompanysBLL.cs 프로젝트: ben889/myb2b
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password">密码</param>
        /// <param name="resultMsg"></param>
        /// <returns></returns>
        public static int login(string username, string password, ref string resultMsg)
        {
            if (username.Trim().Length == 0)
            {
                resultMsg = "帐号不能为空";
                return(-1);
            }
            if (password.Trim().Length == 0)
            {
                resultMsg = "密码不能为空";
                return(-1);
            }
            //password = Common.Utility.MD5Encrypt(password);
            CompanysInfo info = new CompanysDAL().getModel(username, password);

            if (info != null && info.CompanyID > 0)
            {
                try
                {
                    if (info.status == -1)
                    {
                        resultMsg = "帐号已被锁定,请联系管理员";
                        return(-1);
                    }
                    int minite = 60 * 24 * 7;//一星期

                    CookiesHelper.WriteCookie(COOKIES_COMPANY, minite, "", info.CompanyID.ToString());
                    //判断客户端是否存在该cookie,若存在则清除
                    //if (HttpContext.Current.Request.Cookies[COOKIES_COMPANY] != null)
                    //{
                    //    HttpContext.Current.Response.Cookies[COOKIES_COMPANY].Expires = DateTime.Now.AddSeconds(-1);
                    //}
                    ////向客户端浏览器加入
                    //HttpCookie hccompany_id = new HttpCookie(COOKIES_COMPANY);
                    //hccompany_id.Expires = DateTime.Now.AddDays(7);
                    //hccompany_id.Value = info.CompanyID.ToString();

                    //HttpContext.Current.Response.Cookies.Add(hccompany_id);
                }
                catch { }
                return(info.CompanyID);
            }
            resultMsg = "帐号/密码错误";
            return(0);
        }
        public async Task <AppUserModel> Login([FromBody] LoginObject login)
        {
            bool valid;

            HttpContext.Session.Clear();

            valid = await AppUser.Login(contextProvider, login.email, login.password);

            if (!valid)
            {
                HttpContext.Session.Clear();
            }
            else
            {
                CookiesHelper.WriteCookie(HttpContext, CookiesHelper.LoginCookieName, login.email, 1);
            }

            return((AppUserModel)(await contextProvider.GetAppUser()).ToModelObject);
        }