⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 ASP.NET构建的笑傲江湖社区(C#,全源码提供)
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;

namespace xajh
{
	/// <summary>
	/// _default 的摘要说明。
	/// </summary>
	public class _default : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList online;
		protected System.Web.UI.WebControls.TextBox byts_password;
		protected System.Web.UI.WebControls.TextBox byts_username;
		protected System.Web.UI.WebControls.Label byts_copyright;
		protected System.Web.UI.HtmlControls.HtmlForm byts_xajh;
		protected System.Web.UI.WebControls.Literal byts_title;
		protected System.Web.UI.WebControls.LinkButton byts_submit;
		protected System.Web.UI.WebControls.DropDownList myselect;
		protected System.Web.UI.WebControls.LinkButton byts_clear;
		protected System.Web.UI.WebControls.Label byts_starttime;
		protected System.Web.UI.WebControls.Literal byts_errormsg;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (this.Request.Cookies["byts"] == null)
			{
				HttpCookie myc = new HttpCookie("byts");
				myc.Expires = DateTime.Now.AddDays(10);
				myc.Values.Add("nick", "|");
				myc.Values.Add("chat", "");
				this.Response.AppendCookie (myc);
			}
			if (!this.Page.IsPostBack)
			{
				if (this.Request.RawUrl.IndexOf("?love") != -1)
				{
					this.Response.Write ("<html><head><title>我爱你一生一世</title></head><body bgcolor=\"#0080D5\" text=\"#FFFFFF\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FFFF00\"><p>樊赟:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;无论在世界的每一个角落,我都爱你一生一世。</p><p><a target=_blank href=http://9diy.net/go.aspx?type=aboutme>S</a></p></body></html>");
					this.Response.End();
				}
				else
				{
					this.byts_submit.Attributes["onclick"] = "return (check())";
					this.online.Items.Add(var.public_online + " 在线 / " + var.public_inchat + " 聊天");
					ArrayList roomlist = var.public_roomlist;
					for (int i = 0; i < roomlist.Count; i ++)
					{
						this.online.Items.Add("『" + ((x.RoomInfo) this.Application["byts_xajh_chat_roominfo_" + roomlist[i]]).RoomName + "』");
						ArrayList roomonline = (ArrayList) this.Application["byts_xajh_chat_online_" + roomlist[i]];
						foreach(string nickname in roomonline)
						{
							this.online.Items.Add(nickname);
						}
					}
					string cookiename = this.Request.Cookies["byts"]["nick"];
					if (cookiename != "|")
					{
						this.myselect.DataSource = cookiename.Substring(1, cookiename.Length - 2).Split('|');
						this.myselect.DataBind();
					}
					this.myselect.Items.Insert(0, new ListItem("<...空...>",""));
					this.byts_title.Text = var.public_name + " (授权给:" + var.public_user + ",序列号:" + var.public_sn + ")";
					this.byts_starttime.Text = var.public_starttime.ToString();
					this.byts_copyright.Text = "授权给:<font class=\"byts\">" + var.public_user + "</font> 序列号:<font class=\"byts\">" + var.public_sn + "</font> 作者<font class=\"byts\"><a target=_blank href=http://9diy.net/go.aspx?type=aboutme>变异天使</a></font>保留所有权利";
				}
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.byts_submit.Click += new System.EventHandler(this.byts_submit_Click);
			this.byts_clear.Click += new System.EventHandler(this.byts_clear_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void byts_submit_Click(object sender, System.EventArgs e)
		{
			string username = byts_username.Text.Trim();
			string password = byts_password.Text.Trim();
			if (this.Session["info"] != null)
			{
				this.Response.Write ("<script language=javascript type=text/javascript>alert('系统检测到你原来的名字没有退出!\\r\\n系统将直接以旧用户名进入!');top.location.href='ILoveFanYun.aspx'</script>");
				this.Response.End();
			}
			if (username == "")
			{
				this.byts_errormsg.Text = "用户名不能为空!";
				return;
			}
			if (password == "")
			{
				this.byts_errormsg.Text = "密码不能为空!";
				return;
			}
			for (int i = 0; i < username.Length; i ++)
			{
				if ((int) username[i] < 19968 || (int) username[i] > 40870)
				{
					this.byts_errormsg.Text = "用户名非法!用户名只能使用中文!";
					return;
				}
			}
			if (username.Length > 5)
			{
				this.byts_errormsg.Text = "用户名长度不能超过5字符!";
				return;
			}
			if (username == "大家")
			{
				this.byts_errormsg.Text = "用户名不能使用 大家!";
				return;
			}
			if (password.Length < 4)
			{
				this.byts_errormsg.Text = "密码至少需要4位!";
				return;
			}
			if (password == "1111" || password == "0000" || password == "8888" || password == "aaaa" || password == "abcd")
			{
				this.byts_errormsg.Text = "密码太过于简单,容易被他人猜到!";
				return;
			}
			string userip = this.Request.ServerVariables["REMOTE_ADDR"];
			OleDbConnection MyConn = new OleDbConnection(var.public_conn);
			MyConn.Open();
			OleDbCommand MyComm = new OleDbCommand(@"select [id],[密码],[性别],[头像],[等级],[战斗等级],[会员],[门派],[身份],[职业],[注册IP] from [注册用户] where [用户名]='" + username + "'", MyConn);
			OleDbDataReader dr = MyComm.ExecuteReader();
			if (dr.Read())
			{
				password = FormsAuthentication.HashPasswordForStoringInConfigFile(password + dr["注册IP"], "SHA1");
				if (dr["密码"].ToString() != password)
				{
					dr.Close();
					MyConn.Close();
					MyConn.Dispose();
					this.byts_errormsg.Text = "密码错误!请仔细核对!";
				}
				else
				{
					x.UserInfo info = new x.UserInfo();
					info.UserName = username;
					info.DataID = dr["id"].ToString();
					info.RoomID = "false";
					info.LastSave = DateTime.Now;
					info.MsgLine = 0;
					info.LastSaid = DateTime.Now;
					info.Sex = dr["性别"].ToString();
					info.Ico = (int) dr["头像"];
					info.Grade = (int) dr["等级"];
					info.FGrade = (int) dr["战斗等级"];
					info.Gold = (int) dr["会员"];
					info.CloseDoor = false;
					info.MyClass = dr["门派"].ToString();
					info.MyHead = dr["身份"].ToString();
					info.MyJob = dr["职业"].ToString();
					string myid = dr["id"].ToString();
					dr.Close();
					string myonline = username + "|" + info.DataID + "|" + info.Sex + "|" + info.Ico + "|" + info.Grade + "|" + info.FGrade + "|" + info.Gold + "|" + info.CloseDoor + "|" + info.MyClass + "|" + info.MyHead + "|" + info.MyJob;
					this.Application.Lock();
					if (var.public_onlineinfo.ContainsKey(username) == true)
					{
						MyConn.Close();
						MyConn.Dispose();
						this.byts_errormsg.Text = "该用户名正在使用,不能重复登陆!";
						return;
					}
					var.public_onlineinfo.Add(username, myonline);
					var.public_online ++;
					this.Application.UnLock();
					this.Session["info"] = info;
					HttpCookie myc = this.Request.Cookies["byts"];
					myc.Expires = DateTime.Now.AddDays(10);
					myc["chat"] = username;
					myc["nick"] = "|" + username + myc["nick"].Replace("|" + username + "|", "|");
					this.Response.SetCookie (myc);
					try
					{
						MyComm.CommandText = @"update [注册用户] set [登陆次数]=[登陆次数]+1,[最后登陆]='" + DateTime.Now + "',[最后IP]='" + userip + "' where [id]=" + myid;
						MyComm.ExecuteNonQuery();
						MyConn.Close();
						MyConn.Dispose();
					}
					catch
					{
						MyConn.Close();
						MyConn.Dispose();
					}
					this.Response.Redirect ("welcome.aspx");
				}
			}
			else
			{
				dr.Close();
				MyConn.Close();
				MyConn.Dispose();
				this.byts_errormsg.Text = "unreg|" + username;
			}
		}

		private void byts_clear_Click(object sender, System.EventArgs e)
		{
			HttpCookie myc = this.Request.Cookies["byts"];
			myc.Expires = DateTime.Now.AddDays(10);
			myc["nick"] = "|";
			this.Response.SetCookie (myc);
			this.myselect.Items.Clear();
			this.myselect.Items.Add(new ListItem("<...空...>",""));
			this.byts_errormsg.Text = "保存在Cookie中的用户名列表已经成功清除!";
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -