RavenDB 查询以检查用户名和密码
我对 C# 和 RavenDB 相当陌生,所以请原谅我缺乏理解。
我目前有一个 Windows 窗体应用程序。在其中一种表单中,我有两个文本框和一个按钮。这两个文本框用作用户名和密码输入,按钮显然在那里,以便用户可以登录。当用户单击按钮时,将调用一个方法并将两个输入的内容保存在两个字符串变量中。
目前,在我的 RavenDB 数据库中,我创建了两个用户名和密码示例。
如何正确检查用户提供的用户名和密码是否存在于数据库中。
非常感谢任何帮助。
I'm fairly new to C# and RavenDB, so please excuse my lack of understanding.
I currently have a Windows Form Application. In one of the forms, I have two text boxes and one button. These two text boxes serve as the username and password inputs and the button is obviously there so that the user can login. When the user clicks on the button, a method is called and saves the content of the two inputs in two string variables.
At the moment, in my RavenDB Database, I have created two samples of username and password.
How do I appropriately check whether the username and password given from the user exists in the database.
Any help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法可以回答这个问题。
a) 您可以使用 Linq 提供程序查询多个属性
b) 这样做的问题是,这假设您将密码以纯文本形式存储在数据库中,而您绝不应该这样做。
您可以在 RaccoonBlog 的 RavenDB 示例应用程序中看到我们如何实现这一点:
https://github.com/ayende/RaccoonBlog/blob/master/src/RaccoonBlog.Web/Models/User.cs
https://github.com/ayende /RaccoonBlog/blob/master/RaccoonBlog.Web/Areas/Admin/Controllers/LoginController.cs
There are two ways to answer this question.
a) You can query for multiple properties using the Linq provider
b) The problem with this is that this assumes that you are storing the password as plain text in the database, which you should never do.
You can see how we implemented that in RaccoonBlog's RavenDB's sample application:
https://github.com/ayende/RaccoonBlog/blob/master/src/RaccoonBlog.Web/Models/User.cs
https://github.com/ayende/RaccoonBlog/blob/master/RaccoonBlog.Web/Areas/Admin/Controllers/LoginController.cs
作为良好的安全实践,您根本不存储密码,而是存储密码的哈希值。
存储您的密码
读取服务器上的值并生成密码的哈希码。您应该使用加密函数来生成哈希(例如通过 SHA256 )
将文档存储在 User 类型的 Raven DB 中,并包含用户名和哈希密码
检查用户是否传递的凭据是在数据库中
示例代码
As a matter of good security practice you don't store passwords at all, rather you you store the password's hash.
To store your password
Read the values on the server and generate a hashcode of the password. You should use crypto functions to generate hash (such as via SHA256)
Store a document in Raven DB of type User with his username and hashed password
To check if the user with the passed credentials is in the database
Sample code