c#登陆界面登陆时读取txt文本文件,将里面的用户名和密码与combobox和text输入的内容进行匹配,成功则登陆

txt文件格式为:张三空格112233李四空格111111求源代码。... txt文件格式为:
张三 空格112233
李四 空格111111

求源代码。
展开
 我来答
百度网友26c14b1d3
2012-07-16 · TA获得超过336个赞
知道小有建树答主
回答量:472
采纳率:0%
帮助的人:315万
展开全部
若非要用你的思路实现的话,可以参考如下代码。
//加载用户名及密码到Dictionary中
string[] strs = File.ReadAllLines("D:\\test.txt", Encoding.Default);
Dictionary<string, string> UserPwd = new Dictionary<string, string>();
foreach (string str in strs)
{
UserPwd.Add(str.Split(' ')[0].ToString(), str.Split(' ')[1].ToString());
}
//处理
string user = comboBox1.Text.ToString();
string pwd = textBox1.Text.Trim();
if (UserPwd.ContainsKey(user) && UserPwd[user] == pwd)
MessageBox.Show("True,Login In……");
else
MessageBox.Show("False,Can not Login……");

但真不推荐使用你这样的思路,有诸多问题。
swfcy
2012-07-16 · TA获得超过100个赞
知道答主
回答量:100
采纳率:0%
帮助的人:29.8万
展开全部
string UserName = this.TextBox_username.Text;
string Password = this.TextBox_pass.Text;
string Yzm = this.TextBox_yzm.Text;
string Type = this.DropDownList1.SelectedItem.Text;
if (UserName == "")
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('请输入用户名!')", true);
return;
}
if (Password == "")
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('请输入密码!')", true);
return;
}
if (Yzm == "")
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('请输入验证码!')", true);
return;
}
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "md5");
DataSet ds = CoSt.Read("select * from Users where UserName='"+UserName+"' and Password='"+pwd+"'");
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
int UserID = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
int Count = Convert.ToInt32(ds.Tables[0].Rows[0][10].ToString());
string Type_sql = ds.Tables[0].Rows[0]["Type"].ToString();
if (Yzm.ToLower() != Session["CheckCode"].ToString())
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('验证码输入有误!')", true);
return;
}
else
{
if (Type != Type_sql)
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('类型选择有误!')", true);
return;
}
else
{
Count = Count + 1;
CoSt.UpdateCount(UserID, Count);
Session["User"] = UserName;
if (Type == "学生")
{
Response.Redirect("../Student/SIndex.aspx");
}
if (Type == "学校")
{
Response.Redirect("../Student/SIndex.aspx");
}
if (Type == "企业")
{
Response.Redirect("../Student/SIndex.aspx");
}
}
}
}
else
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "UpdateSucceed", "alert('登录失败,请检查后再试!')", true);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
geto1080
2012-07-16 · TA获得超过320个赞
知道小有建树答主
回答量:1359
采纳率:100%
帮助的人:513万
展开全部
登录建议卸载web.config配置文件中,也可以使用XML文件,这样更简单,如果txt文件就要调用IO,读写文件了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
月光uDu
2012-07-16 · TA获得超过127个赞
知道答主
回答量:88
采纳率:0%
帮助的人:61.1万
展开全部
用File.IO下的FileStream StreamReader
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
uusl
2018-01-09
知道答主
回答量:30
采纳率:0%
帮助的人:15.1万
引用likezhou1130的回答:
若非要用你的思路实现的话,可以参考如下代码。
//加载用户名及密码到Dictionary中
string[] strs = File.ReadAllLines("D:\\test.txt", Encoding.Default);
Dictionary<string, string> UserPwd = new Dictionary<string, string>();
foreach (string str in strs)
{
UserPwd.Add(str.Split(' ')[0].ToString(), str.Split(' ')[1].ToString());
}
//处理
string user = comboBox1.Text.ToString();
string pwd = textBox1.Text.Trim();
if (UserPwd.ContainsKey(user) && UserPwd[user] == pwd)
MessageBox.Show("True,Login In……");
else
MessageBox.Show("False,Can not Login……");

但真不推荐使用你这样的思路,有诸多问题。
展开全部
此源码不能用
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式