zoukankan      html  css  js  c++  java
  • 尝试用户自动登录

    //尝试用户自动登录

    /// <summary>
            /// 尝试自动登录 或填充密码
            /// </summary>
            /// <param name="context"></param>
            /// <returns>自动登录后的状态:成功,填充密码,失败继续</returns>
            public static ConstStringHelper.AutoLoginResult TryAutoLoginOrMemoryPwd(HttpContext context,out string username,out string password)
            {
                username = ""; password = "";
                //尝试自动登录
                HttpCookie cookie_chkAutoLogin = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_CHKAUTOLOGIN];
                if (cookie_chkAutoLogin!=null && cookie_chkAutoLogin.Value=="true") 
                {
                    HttpCookie cookie_username = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_USERNAME];
                    HttpCookie cookie_password = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_PASSWORD];
                    if (cookie_username != null && cookie_password!=null)
                    {
                        if (CheckLoginStatus(context, cookie_username.Value, CommonHelper.DesDecode(cookie_password.Value)) == ConstStringHelper.LoginResult.OK)
                        {
                            return ConstStringHelper.AutoLoginResult.AutoLogin;
                        }
                    }
                }
                //尝试填充密码
                HttpCookie cookie_chkMemoryPwd = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_CHKMEMORYPWD];
                if (cookie_chkMemoryPwd != null && cookie_chkMemoryPwd.Value == "true")
                {
                    HttpCookie cookie_username = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_USERNAME];
                    HttpCookie cookie_password = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_PASSWORD];
                    if (cookie_username != null && cookie_password != null)
                    {
                        username = cookie_username.Value;
                        password = CommonHelper.DesDecode(cookie_password.Value);
                        return ConstStringHelper.AutoLoginResult.MemoryPwd;
                    }
                }
                return ConstStringHelper.AutoLoginResult.NO;
            }

    //存Cookie

    /// <summary>
            /// 把用户名和密码 存入cookie
            /// </summary>
            /// <param name="context"></param>
            /// <param name="username"></param>
            /// <param name="password"></param>
            public static void StoreCookie(HttpContext context, string chkMemoryPwd, string chkAutoLogin, string username, string password)
            {
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_CHKMEMORYPWD) { Value = chkMemoryPwd, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_CHKAUTOLOGIN) { Value = chkAutoLogin, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_USERNAME) { Value = username, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_PASSWORD) { Value = CommonHelper.DesEncode(password), Expires = DateTime.Now.AddDays(7) });
            }

    //存Session

    /// <summary>
            /// 把用户id和用户名 存入session 
            /// </summary>
            /// <param name="context"></param>
            /// <param name="id"></param>
            /// <param name="username"></param>
            public static void StoreSession(HttpContext context,long id,string username)
            {
                context.Session[ConstStringHelper.ADMINSESSION_ID] = id;
                context.Session[ConstStringHelper.ADMINSESSION_USERNAME] = username;
            }
  • 相关阅读:
    Java 截取目标长度英文单词字符串 要求避免截断单词
    mysql报Fatal error encountered during command execution的解决办法
    PostgreSQL 学习01 Centos7.6安装PostgreSQL10
    Ubuntu14.04 + KinectV2驱动安装 以及 Ros接口(基于网上方法试错 改进版)
    传统定位方法简介--------里程计、IMU惯性传感器以及光电编码器等
    Vue.js 动态绑定class
    MongoDB数据导入导出成csv或者json
    exception 'yiiaseErrorException' with message 'Class 'MongoClient' not found'
    exception 'DOMException' with message 'Invalid Character Error' Php + Mongodb
    浅谈Angular的 $q, defer, promise
  • 原文地址:https://www.cnblogs.com/adolphyang/p/4842010.html
Copyright © 2011-2022 走看看