using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ChatLogin : System.Web.UI.Page
{
//user数组存放用户名和密码。实际工程数据应从数据库中获取。
string[,] user = { { "张三", "111111" }, { "王五", "111111" }, { "李四", "111111" } };
protected void Page_Load(object sender, EventArgs e)
{
//焦点定位在“用户名”文本框
txtName.Focus();
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//在数组user中循环查找能匹配的用户名和密码
for (int i = 0; i <= 2; i++)
{
if (txtName.Text == user[i, 0] && txtPassword.Text == user[i, 1]) //匹配成功
{
//将用户名存入Session变量user
Session["user"] = user[i, 0];
//重定向到聊天页
Response.Redirect("/Chat.htm");
return;
}
}
//在数组user中找不到匹配的用户,输出“用户名或密码错误!”提示信息
Response.Write("<script type='text/javascript'>alert('用户名或密码错误!');</script>");
}
}