登录状态失败 [英] Login status is failed

查看:154
本文介绍了登录状态失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用c#asp.net中的会话编写了登录应用程序。

但是没有进入欢迎页面。消息是用户sa的登录失败。

home.aspx背后的业务逻辑:

I have written login application using session in c# asp.net .
but instead of going to the welcome page. the message is "login of the user sa is failed".
THe businesss logic behind the home.aspx:

try
        {
            conn = new SqlConnection("Data Source=LENOVO;Initial Catalog=sample;User ID=sa;Password=***********");
            conn.Open();
            Response.Write("connection to databaase is established");
            String query = "select count(*) from tblRegister where name='" + txtuser.Text + "'and Password'" + txtpass.Text + "'";
            cmd = new SqlCommand(query, conn);
            String output = cmd.ExecuteScalar().ToString();
            if (output == "1")
            {
                Session["user"] = txtuser.Text;
                Response.Redirect("~/Welcome.aspx");
            }
            else
            {
                Response.Write("Login failed");

            }
        }
        catch (Exception ex)
        {
            Response.Write("sorry" + ex.Message + "\n");
            Response.Write(ex.HelpLink);
            //Response.Write(ex.InnerException);
        }
        finally
        {
            conn.Close();
            Response.Write("Connection closed");
        }
    }
}





我尝试了什么:



我试过这个:



What I have tried:

I have tried this:

String query = "select * from tblRegister where name='" + txtuser.Text + "'and Password'" + txtpass.Text + "'";

推荐答案

String query = "select count(*) from tblRegister where name='" + txtuser.Text + "'and Password'" + txtpass.Text + "'";



Not你的问题的解决方案,但你有另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]






我检查了你的数据库查询并发现了一些问题所以请尝试下面的查询 -



Hi,

I checked your database query and found some issue so try below query for this-

String query = "select * from tblRegister where name='" + txtuser.Text + "'and Password = '" + txtpass.Text + "'";





您在密码字段后错过了等号(=)。



You have missed equal (=) sign after Password field.


您的连接string



Your connection string

Data Source=LENOVO;Initial Catalog=sample;User ID=sa;Password=***********





无效。密码对sa帐户无效,我们无法告诉您为什么我们无法访问您的数据库,您需要自己解决。



isn't valid. The password isn't valid for the sa account, we can't tell you why as we have no access to your database, you'll need to work that out yourself.


这篇关于登录状态失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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