如何从文本文件表单验证用户名和密码

发布于 2024-08-29 07:00:33 字数 98 浏览 1 评论 0原文

我有一个登录表单,其中包含用户名和密码作为用户的输入,我想从文本文件验证这些登录凭据。我该怎么做呢?我知道如何写入数据和读取数据。但如何仅读取特定数据。或检查用户名密码组合是否存在。

I have a login form that has Username and password as inputs from user and I want to validate these login credentials from a text file. How can I do it? I know how to write data and read data..but how to read only specific data.or check whether username password combination exists or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

a√萤火虫的光℡ 2024-09-05 07:00:33

有什么理由必须使用纯文本文件吗?正如约书亚所说,这是存储安全信息的糟糕方法。

在 .NET 中,标准方法是使用应用程序配置文件来存储用户名/密码(例如 app.config 或 web.config)并使用数据保护 API (DPAPI) 或 System.Security.Cryptography.ProtectedData 加密密码班级。

Jon Galloway 提供了 关于如何做到这一点的不错的教程

Is there any reason you have to use a plain text file? As Joshua says this is a poor way to store security information.

In .NET a standard approach is to use an application configuration file to store username/password (eg. app.config or web.config) and encrypt the password using the Data Protectction API (DPAPI) or the System.Security.Cryptography.ProtectedData class.

Jon Galloway provides a decent tutorial on how to do this.

向日葵 2024-09-05 07:00:33

跳过将密码存储在文本文件中的不良做法(尤其是未加密的情况),您将需要想出某种文件格式。

一个非常基本的文件可能就像您读取的 ini 文件:

[users]
username1=password1
username2=password2

您的算法将查找 [users] 标头,然后读取每一行,在等号上分割该行并比较信息并保留阅读直到找到匹配项、文件末尾或可能的另一个部分。

我不确定您以前是否曾经使用过用户身份验证,但以纯文本形式存储密码被认为是不好的做法,因为如果密码被泄露,会出现严重的安全问题。您通常希望使用单向哈希(例如 SHA-1 或 SHA-256)对用户密码进行哈希处理(可能使用已知的盐)并将其发送到您的应用程序并存储它。这样,即使您以某种方式受到损害,您也永远不会知道实际密码。

Skipping over the bad practice of storing passwords in a text file (especially if it isn't encrypted) you will need to come up with some sort of file format.

A very basic file could be like an ini file that you read:

[users]
username1=password1
username2=password2

Your algorithm would look for the [users] header, then read each line, split the line on the equal sign and compare the information and keep reading until you find a match, the end of the file, or possibly another section.

I'm not sure if you have ever worked with user authentication before but it is considered bad practice to store passwords in plain text because of the serious security issue if they are compromised. You generally want to use a one-way hash (like SHA-1 or SHA-256) to hash the users password (possibly with a known salt) and send that to your application and store that instead. That way you never know the actual password even if you are compromised in some way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文