如何根据数据库验证用户名是否有效 [英] how to Verify if the username is valid based on the database

查看:68
本文介绍了如何根据数据库验证用户名是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据数据库验证用户名是否有效(数据库的ms访问类型为oledb连接).

How to Verify if the user name is valid based on the database (data base is of ms access type is oledb connection).

推荐答案

this[^] might help you.


嘿!

有几种方法可以做到这一点.您需要提供更多信息:
-用户名是在文本框中输入的还是Windows用户名?
-是否包含密码? (是->密码是否已加密?)

基础很简单.

创建一个OleDbConnection对象

Hey!

There are several ways to do so. You need to provide a little more information :
- Is the username entered in a textbox or the Windows username?
- Is there a password involved? (yes -> is the password encrypted?)

The basics is simple.

Create an OleDbConnection object

using (OleDbConnection myConn = new OleDbConnection(connectionstring))
{



(connectionstring是用于连接到数据库的连接字符串,请参见
此网站 [ ^ ]查找正确的连接字符串

然后,您需要查询数据库中的某个表,例如:

用户的位置上选择 ID,密码(登录= =" LoginName '')

ID Password 是数据库表中名为 Users
的字段
现在您需要创建一个OleDbCommand对象:



(connectionstring is the connectionstring to connect to your database, see this website[^] to find the correct connectionstring

Then you need to query a certain table in your database, for example :

SELECT ID, Password FROM Users WHERE (Login = ''LoginName'')

ID and Password are fields in the database table called Users

Now you need to create an OleDbCommand object :

using (OleDbCommand dbCommand = new OleDbCommand("SELECT ID, Password FROM Users WHERE (Login = ''LoginName'')", myCommand))
{



最后,您需要从查询中提取结果:



Finally you need to extract the result from your query :

myConn.Open() // Open the database connection
OleDbDataReader rdrResult = dbCommand.ExecuteReader();

// Check the user ID and Password

myConn.Close(); // Close the database connection

}
}



上面的描述是一种快速而又肮脏"的方式来检查用户名,还有更优雅的方式来检查用户的凭据,这些方式很大程度上取决于您的需求.

祝你好运!

爱德华



The above description is a ''quick and dirty'' way to check the username, there are far more elegant ways to check a user''s credentials these however strongly depend on your needs.

Good luck!

Eduard


这篇关于如何根据数据库验证用户名是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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