简体   繁体   English

如何检查数据库中是否存在带有输入密码的网络登录名?

[英]How check in the database if there is a network login with the password that was entered?

I wonder how can I create a code to check in the database if there is a network login with the password that i Entered. 我想知道如何创建代码来检查数据库中是否存在使用我输入的密码的网络登录名。 I'm doing this in the "Global.asax" 我正在“ Global.asax”中执行此操作

Thank you all! 谢谢你们!

EDIT: The code that i tried to write 编辑:我尝试编写的代码

        SqlCommand comando = new SqlCommand("Select * from Usuario where  = @UserID", conexao);
        comando.Connection = conexao;
        SqlParameter param = new SqlParameter();
        param.ParameterName = "@UserID";
        param.Value = login;
        comando.Parameters.Add(param);

I did something like this, but using Active Directory. 我做了类似的事情,但是使用了Active Directory。 Check it Out: 看看这个:

The task was to check in Active Directory if there is a network login 任务是检查Active Directory中是否存在网络登录名

        try
        {

            using (var entry = new DirectoryEntry("LDAP://" + dominio, dominio + "\\" + login, senha))
            {

                using (var directorySearcher = new DirectorySearcher(entry))
                {
                    matricula = TratarLDAPInjection(matricula);

                    directorySearcher.Filter = "(sAMAccountName=" + matricula + ")";

                    SearchResult result = directorySearcher.FindOne();

                    if (result == null)
                    {
                        throw new AguException(string.Format("Não é possível localizar o usuário de matrícula {0} no banco de dados da MyEnterprise.", matricula));
                    }
                }
            }
        }
        catch
        {
          Response.Redirect("~/Erro.aspx");
        }

Well your sql query should be something like : 那么您的SQL查询应该是这样的:

SELECT * FROM Usuario WHERE [username]=@UserId AND [password]=@Password

Then you can bind the values @UserId and @Password, like you already did in your code. 然后,您可以像在代码中一样绑定值@UserId和@Password。

(You need to replace [username] and [password] with the correct column names from your table) (您需要用表中的正确列名替换[用户名]和[密码])

EDIT : 编辑:

You can get the result by using : 您可以使用以下方法获得结果:

SqlDataReader reader = comando.ExecuteReader();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM