-1

我正在做一个项目,我需要为学校网站制作 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....!!!";
    }
}
4

2 回答 2

1

当您获得用户名时,您可以使用数据集检索有关该用户的所有详细信息并相应地显示在 secure.aspx 中。

建议:不要直接使用sql查询(容易被sql注入),你应该使用存储过程..并且不要以纯文本存储密码。为什么要为相同的数据检索两次数据。

于 2012-06-15T16:11:29.527 回答
0

这不会解决你所有的问题,但我会阅读这篇文章

http://www.codehighstreet.com/Articles/overview_of_membership_and_installing_sql_membership_provider-part_1/overview_of_membership_and_installing_sql_membership_provider-part_1.aspx

您当前的用户名和密码解决方案根本不是很安全,因为您当前将密码存储为纯文本。本文介绍了如何安装和设置用户名和密码数据库以及使用一些控件来为您处理身份验证

于 2012-06-15T14:36:39.987 回答