我正在做一个项目,我需要为学校网站的VLE系统。我使用Visual Web Developer 2008,C#和SQL数据库。我需要做的是,当一个学生使用他们的用户名和密码登录时,他们应该从数据库中显示他们的具体信息(如从SQL中显示的课程名称,学生ID,电子邮件和名称等)我已经创建了登录页面:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
con.Open();
string cmdStr = "select count (*) from Registration where UserName ='" + TextBox1.Text + "'";
SqlCommand checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
String cmdStr2 = "select password from Registration where UserName ='" + TextBox1.Text + "'";
SqlCommand pass = new SqlCommand(cmdStr2, con);
String password = pass.ExecuteScalar().ToString();
con.Close();
if (password == TextBox2.Text)
{
Session["New"] = TextBox1.Text;
Response.Redirect("secure.aspx");
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Password....!!!";
}
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid UserName....!!!";
}
}
2条答案
按热度按时间toiithl61#
当你得到用户名,然后你可以去数据集检索有关该用户的所有细节,并显示在安全。aspx相应的
建议:不要直接使用sql查询(容易受到sql注入的影响),你应该使用存储过程。.也不要以纯文本形式存储密码。为什么你检索数据两次相同的数据.
p5fdfcr12#
这不会解决你所有的问题,但我会读this article。
您当前的用户名和密码解决方案不是很安全,因为您当前将密码存储为纯文本。本文将介绍如何安装和设置用户名和密码数据库,以及如何使用一些控件来处理身份验证