我需要有关Asp.net登录页面的帮助 [英] I need help with a Login page on Asp.net

查看:68
本文介绍了我需要有关Asp.net登录页面的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录页面,从一个表中读取另一个表中的用户名和密码。

一旦用户登录,它就会将用户重定向到他们的页面。有没有办法可以将另一个用户重定向到另一个页面?这是我的代码。

I have a login page that reads from one table the username and the password from another table.
Once the user logins it redirects the user the their page. Is there any way that it can redirect another user to another page? Here is my code.

public partial class Login : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
        con.Open();

        string cmdStr = "select count(*) from TableCEO where EmailAddress='" + TextBox1.Text + "'";
        SqlCommand Checkuser = new SqlCommand(cmdStr, con);
        int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
        if (temp == 1)
        {
            string cmdStr2 = "Select Password from TablePass where Password='" + TextBox2.Text + "'";
            SqlCommand pass = new SqlCommand(cmdStr2, con);
            string password = pass.ExecuteScalar().ToString();
            con.Close();

            if (password == TextBox2.Text)
            {
                Session["New"] = TextBox1.Text;
                Response.Redirect("Welcome.aspx");
            }
            else
            {
                Label1.Visible = true;
                Label1.Text = "Invalid Password!!!";
            }
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "Invalid UserName!!!";
        }
    }
}

推荐答案

想象一下这种情况:

用户(智能用户)想要登录。他在电子邮件文本框中写入 me@mail.com 并且 pwd 在密码文本框中。此输入将生成以下sql-queries:

Just imagine this scenario:
A user (smart one) wants to log in. He writes me@mail.com in the Email textbox and pwd in the password textbox. This input will generate the following sql-queries:
select count(*) from TableCEO where EmailAddress='me@mail.com'






and

Select Password from TablePass where Password='pwd'



这没问题。





现在成像该用户写入''或1 = 1或1 =''在电子邮件文本框中,密码文本框中的''或LEN(密码)> 0或密码=''



此输入将生成以下sql-queries:


That''s no problem.


Now imaging that this user writes '' or 1=1 or 1='' in the email textbox, and '' or LEN(Password)>0 or Password='' in the password textbox.

This input will generate the following sql-queries:

select count(*) from TableCEO where EmailAddress='' or 1=1 or 1=''






and

Select Password from TablePass where Password='' or LEN(Password)>0 or Password=''





你在这里看到问题吗?它被称为SQL注入。使用SqlParameters很容易防止。你真的应该读一读它。



MSDN - 如何:保护免受SQL在ASP.NET中注入 [ ^ ]



您绝不应将密码作为明文存储在数据库中。这很容易避免。我写了一篇关于此的文章:初学者指南以安全的方式存储密码 [ ^ ]


这篇关于我需要有关Asp.net登录页面的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆