Ejemplo n.º 1
0
 /// <summary>
 /// 新增用户
 /// </summary>
 /// <param name="userinfo"></param>
 /// <returns></returns>
 public bool Add(UserInfo userinfo)
 {
     userinfo.UserId = Guid.NewGuid().ToString();
     //加密
     userinfo.UserPassword = SHAEncrypt.SHA128(userinfo.UserPassword);
     userinfo.CreateTime = DateTime.Now;
     return dal.Add(userinfo);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 新增用户
 /// </summary>
 /// <param name="userinfo"></param>
 /// <returns></returns>
 public bool Add(UserInfo userinfo)
 {
     IList<SqlParameter> arrParameter = new List<SqlParameter>();
     arrParameter.Add(new SqlParameter { ParameterName = "@userid", Value = userinfo.UserId, DbType = DbType.String });
     arrParameter.Add(new SqlParameter { ParameterName = "@username", Value = userinfo.UserName, DbType = DbType.String });
     arrParameter.Add(new SqlParameter { ParameterName = "@password", Value = userinfo.UserPassword, DbType = DbType.String });
     arrParameter.Add(new SqlParameter { ParameterName = "@createtime", Value = userinfo.CreateTime, DbType = DbType.DateTime });
     return SqlHelper.ExecteNonQueryText("INSERT INTO UserInfo (user_id,user_name,user_password,create_time) VALUES(@userid,@username,@password,@createtime)", arrParameter.ToArray()) > 0;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置用户缓存
        /// </summary>
        /// <param name="info">用户信息类</param>
        /// <param name="Timeout">缓存时间</param>
        public static void SetUserInfo(UserInfo info, TimeSpan Timeout)
        {
            //加密用户ID
            string key = DESEncrypt.Encode(info.UserId);

            //将加密数据保存到cookie中
            CookieHelper.SetCookie("UserId", key);

            //缓存用户信息20分钟
            CacheHelper.SetCache(info.UserId, info, Timeout);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public UserInfo Login(string username, string password)
        {
            IList<SqlParameter> arrParameter = new List<SqlParameter>();
            arrParameter.Add(new SqlParameter { ParameterName = "@username", Value = username, DbType = DbType.String });
            arrParameter.Add(new SqlParameter { ParameterName = "@userpassword", Value = password, DbType = DbType.String });
            arrParameter.Add(new SqlParameter { ParameterName = "@result", DbType = DbType.Byte,Direction=ParameterDirection.Output });
            DataTable dtResult = SqlHelper.ExecuteDataSetProducts("myblogs_loginAndQry", arrParameter.ToArray()).Tables[0];

            //获取登录结果(1:成功,0:失败)
            int resultCount = Functions.ToConvert<int>(arrParameter.FirstOrDefault(p => p.ParameterName == "@result").SqlValue.ToString());
            if (resultCount == 1)
            {
                UserInfo info = new UserInfo
                {
                    UserId = Functions.ToConvert<string>(dtResult.Rows[0]["user_id"]),
                    UserName = Functions.ToConvert<string>(dtResult.Rows[0]["user_name"]),
                    UserPassword = Functions.ToConvert<string>(dtResult.Rows[0]["user_password"]),
                    CreateTime = Functions.ToConvert<DateTime>(dtResult.Rows[0]["create_time"]),
                    LoginTime = Functions.ToConvert<DateTime>(dtResult.Rows[0]["login_time"])
                };
                return info;
            }
            return null;
        }
Ejemplo n.º 5
0
 public bool Add(UserInfo userinfo)
 {
     throw new NotImplementedException();
 }