检查数据库中的用户名和密码 [英] check username and password in database

查看:92
本文介绍了检查数据库中的用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在为我的应用程序创建一个登录屏幕,我想在其中存储用户名和密码在数据库表中的
。我想把一个连接到数据库的

组合框拉出用户名,然后用

a文本框让用户输入密码。


有人能告诉我如何将文本框的内容与数据库中的

密码进行比较吗?


谢谢,

Kevin

解决方案

" Kevin O''Brien" < ko ***** @ nshs.eduwrote在

新闻:u5 ************** @ TK2MSFTNGP04.phx.gbl:
< blockquote class =post_quotes>
我在我的应用程序的屏幕上创建一个标志,我想在这里使用
将用户名和密码存储在数据库表中。我正在考虑将一个组合框连接到数据库以提取

用户名然后有一个文本框供用户输入他们的


密码。



相反提示用户名/密码 - 然后运行查询:

SELECT COUNT(1)FROM USERS WHERE UserName = @UserName AND密码=

@Password


使用SQLParameters来避免注入攻击。




所以你说我应该创建2个未绑定的文本框来提示

用户名和密码并命名文本框UserName和Password?然后我就可以从我的VB代码中运行这个SQL select语句了吗?


很抱歉这个简单的问题,但这是我第一次查询
数据库。


谢谢,

凯文



" ;垃圾邮件捕手 < sp ********** @ rogers.comwrote in message

news:Xn ******************** *************@127.0.0.1 ...


" Kevin O''Brien" < ko ***** @ nshs.eduwrote在

新闻:u5 ************** @ TK2MSFTNGP04.phx.gbl:
< blockquote class =post_quotes>
>我在我的应用程序的屏幕上创建一个标志,我想在其中将用户名和密码存储在数据库表中。我正在考虑将一个组合框连接到数据库以提取
用户名,然后有一个文本框供用户输入他们的密码。



提示输入用户名/密码 - 然后运行查询:

SELECT COUNT(1)FROM USERS WHERE UserName = @UserName和密码=

@Password


使用SQLParameters来避免注入攻击。



" Kevin O''Brien" < ko ***** @ nshs.eduwrote在

新闻:Ol ************** @ TK2MSFTNGP03.phx.gbl:
< blockquote class =post_quotes>
所以你说我应该创建2个未绑定的文本框来提示

用户名和密码并命名文本框UserName和Password?

然后我可以直接从我的VB代码运行这个SQL select语句?



确切地说; )

要查询数据库,你可以这样做:


Dim命令为新的SqlClient.SqlCommand

Command.Connection = MyConnectionObject

Command.CommandText =" SELECT COUNT(1)FROM TABLE WHERE UserName =

@UserName AND Password = @ Password"


Command.Parameters.Add(New SqlClient.SqlParameter(" @ UserName",

txtUserName.text))

Command.Parameters.Add(New SqlClient.SqlParameter (" @ UserName",

txtPassword.text))


''如果计数0表示用户名+密码匹配

如果Command.ExecuteScalar 0那么

MsgBox(成功登录)

否则

MsgBox(再试一次)

结束如果


Hello,

I am creating a sign on screen for my application in which I want to store
the username and password in a database table. I was thinking of putting a
combo box connected to the database to pull up the usernames and then having
a textbox for the user to enter their password.

Can someone tell me please how to compare the contents of the textbox to the
password in the database?

Thank you,
Kevin

解决方案

"Kevin O''Brien" <ko*****@nshs.eduwrote in
news:u5**************@TK2MSFTNGP04.phx.gbl:

I am creating a sign on screen for my application in which I want to
store the username and password in a database table. I was thinking
of putting a combo box connected to the database to pull up the
usernames and then having a textbox for the user to enter their
password.

Rather prompt for the username/password - then run the query:

SELECT COUNT(1) FROM USERS WHERE UserName = @UserName AND Password =
@Password

Use SQLParameters to avoid injection attacks.


Hi,

So you are saying I should created 2 unbound textboxes to prompt for
username and password and name the textboxes UserName and Password? Then I
can run this SQL select statement right from my VB code?

Sorry for the simple questions but this is my first crack at querying a
database from VB.

Thanks,
Kevin


"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn*********************************@127.0.0.1 ...

"Kevin O''Brien" <ko*****@nshs.eduwrote in
news:u5**************@TK2MSFTNGP04.phx.gbl:

>I am creating a sign on screen for my application in which I want to
store the username and password in a database table. I was thinking
of putting a combo box connected to the database to pull up the
usernames and then having a textbox for the user to enter their
password.


Rather prompt for the username/password - then run the query:

SELECT COUNT(1) FROM USERS WHERE UserName = @UserName AND Password =
@Password

Use SQLParameters to avoid injection attacks.



"Kevin O''Brien" <ko*****@nshs.eduwrote in
news:Ol**************@TK2MSFTNGP03.phx.gbl:

So you are saying I should created 2 unbound textboxes to prompt for
username and password and name the textboxes UserName and Password?
Then I can run this SQL select statement right from my VB code?

Exactly ; )
To query the DB, you can do:

Dim Command As New SqlClient.SqlCommand
Command.Connection = MyConnectionObject
Command.CommandText = "SELECT COUNT(1) FROM TABLE WHERE UserName =
@UserName AND Password = @Password"

Command.Parameters.Add(New SqlClient.SqlParameter("@UserName",
txtUserName.text))
Command.Parameters.Add(New SqlClient.SqlParameter("@UserName",
txtPassword.text))

''If count 0 means username + password matched
If Command.ExecuteScalar 0 Then
MsgBox("Successful Login")
Else
MsgBox("Try Again")
End If


这篇关于检查数据库中的用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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