Пример #1
0
        protected void regist(Object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            else
            {
                //变量和ID不可重名
                UserInfo newUser = new UserInfo();
                newUser.num   = name.Text;
                newUser.name  = name_real.Text;
                newUser.pwd   = Md5encryption.md5encryption(password.Text);
                newUser.phone = phone.Text;
                newUser.email = email.Text;
                for (int i = 0; i < newUser.name.Length; i++)
                {
                    if (newUser.name[i] == '\\' || newUser.name[i] == '*' || newUser.name[i] == '\"')
                    {
                        MessageBox.Show("姓名不可以包含敏感词汇");
                        return;
                    }
                }

                string access_token = (string)Session["access_token"];
                int    errcode      = registerADO.addNewUser(newUser, access_token);
                if (errcode == 0)
                {
                    MessageBox.Show("注册成功,前往登录");
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    MessageBox.Show("手机号绑定失败,错误码:" + errcode + ",请联系管理员************");
                }
            }
        }
Пример #2
0
        protected void login(object sender, EventArgs e)
        {
            //防止服务器请求过多
            if ((int)Application["UserOnLineCnt"] == 100)
            {
                //MessageBox.Show("当前登录人数爆满,请稍后再试"+(int)Application["UserOnLineCnt"]);
                MessageBox.Show("当前登录人数爆满,请稍后再试");
                return;
            }


            if (login_name.Text == "" || login_password.Text == "")
            {
                MessageBox.Show("请输入用户名和密码再登陆");
                return;
            }

            //在这里判断是否是当前登录
            //首先获取当前用户的IP地址
            string ipAddress = Request.ServerVariables["REMOTE_ADDR"];

            //MessageBox.Show(ipAddress);
            //获取表中的IP地址
            try
            {
                Hashtable hOnline = (Hashtable)Application["num_id"];//读取全局变量
                if (hOnline != null)
                {
                    IDictionaryEnumerator idE = hOnline.GetEnumerator();
                    while (idE.MoveNext())
                    {
                        if (idE.Key != null && idE.Key.ToString().Equals(login_name.Text))//如果当前用户已经登录,
                        {
                            //说明找到了,获取num上次登录的IP地址
                            string ipaddress = idE.Value.ToString();
                            if (ipaddress == (string)Request.ServerVariables["REMOTE_ADDR"])
                            {
                                //无需操作
                            }
                            else
                            {
                                MessageBox.Show("异地登陆,请使用手机号登录");
                                return;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    hOnline = new Hashtable();//MessageBox.Show("不存在");
                }
                //如果可以到这里就更新一下。不存在或者登陆成功更新
                hOnline[login_name.Text] = Request.ServerVariables["REMOTE_ADDR"];
                Application.Lock();
                Application["num_id"] = hOnline;
            }
            catch (Exception ee)
            {
                Application.UnLock();
            }
            finally
            {
                Application.UnLock();
            }


            //query字段
            string   num          = login_name.Text;
            string   access_token = (string)Session["access_token"];
            UserInfo loginUser    = registerADO.getUserByNum(num, access_token);

            if (loginUser != null)
            {
                if (loginUser.pwd == Md5encryption.md5encryption(login_password.Text.Trim()))
                {
                    MessageBox.Show("登陆成功");
                    Session["num"]    = loginUser.num;
                    Session["pwd"]    = loginUser.pwd;
                    Session["name"]   = loginUser.name;
                    Session["email"]  = loginUser.email;
                    Session["phone"]  = loginUser.phone;
                    Session["roleid"] = loginUser.roleid;
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                    return;
                }
            }
            else
            {
                MessageBox.Show("用户名或密码错误");
                return;
            }


            if (Request.Cookies["UserName"] == null || Request.Cookies["PassWord"] == null)
            {
                //没有cookies说明没有登陆过,新建一个Cookies
                //值设置为当前登录名,过期时间设置为3天,添加到Response中去
                HttpCookie userCookie = new HttpCookie("UserName", login_name.Text.Trim());
                //userCookie.Value = "defaultName";
                //过期日期为日期时间
                //在当前天数上添加3天
                userCookie.Expires = DateTime.Now.AddDays(3);
                Response.Cookies.Add(userCookie);
                HttpCookie pwdCookie = new HttpCookie("PassWord", Md5encryption.md5encryption(login_password.Text.Trim()));

                userCookie.Expires = DateTime.Now.AddDays(3);
                Response.Cookies.Add(pwdCookie);
            }
            else
            {
                //将数据存入cookies中
                //这个cookie只有一个值所以直接Value
                //该cookie更新值和过期时间即可
                Response.Cookies["UserName"].Value   = login_name.Text.Trim();
                Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(3);
                Response.Cookies["PassWord"].Value   = Md5encryption.md5encryption(login_password.Text.Trim());
                Response.Cookies["PassWord"].Expires = DateTime.Now.AddDays(3);
            }


            Session["login"] = true;
            //MessageBox.Show(Session.SessionID);
            Session.Timeout = 20;
            //Session["cunchu1"] = "可以存储多个数据";
            //Session.Add("cunchu2", "这样也能存");
            //Session.Abandon();

            //会有出现死锁的问题
            try
            {
                /* List<string> list = loginList.getUserList();
                 * if (list == null)
                 * {
                 *   loginList.addUser(login_name.Text);
                 * }
                 * else
                 * {
                 *   for (int i = 0; i < list.Count; i++)
                 *   {
                 *       MessageBox.Show(list[i]);
                 *   }
                 * }*/


                //利用Session来实现单点登录
                Hashtable hOnline = (Hashtable)Application["Online"];//读取全局变量
                if (hOnline != null)
                {
                    IDictionaryEnumerator idE = hOnline.GetEnumerator();
                    string strKey             = "";
                    while (idE.MoveNext())
                    {
                        if (idE.Value != null && idE.Value.ToString().Equals(login_name.Text))//如果当前用户已经登录,
                        {
                            //already login
                            strKey          = idE.Key.ToString();
                            hOnline[strKey] = "XX";//将当前用户已经在全局变量中的值设置为XX,代表被顶下线
                            //这个SessionID为XX说明这个SessionID被顶下线,重新登陆重新写入SessionID
                            //每次登录都判断,因为用户名唯一,SessionID唯一,所以这个查找唯一//每次只存最近登录的
                            break;
                        }
                    }
                }
                else
                {
                    hOnline = new Hashtable();
                }

                hOnline[Session.SessionID] = login_name.Text;//初始化当前用户的
                Application.Lock();
                Application["Online"]        = hOnline;
                Application["UserOnLineCnt"] = (int)Application["UserOnLineCnt"] + 1;
            }
            catch (Exception ee)
            {
                Application.UnLock();
            }
            finally
            {
                Response.Redirect("Search.aspx");
            }


            /*}
             * }
             * }
             * if (flag)
             * {
             * MessageBox.Show("无效用户名或密码");
             * login_name.Text = "";
             * login_password.Text = "";
             * }
             * sdr.Close();
             * conn.Close();*/
        }
Пример #3
0
 public string getEncryption()
 {
     MessageBox.Show(login_password.Text);
     return(Md5encryption.md5encryption(login_password.Text.Trim()));
 }