How to confirm username and password from a text form
I have a login form that has a username and password as input from a user, and I want to validate those 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 if a combination of username passwords exists.
a source to share
Is there a reason why you should be using a regular text file? As Joshua says, this is a bad way to store security information.
In .NET, the standard approach is to use an application configuration file to store the username / password (such as app.config or web.config) and encrypt the password using the Data Protection API (DPAPI) or System.Security. Cryptography class .ProtectedData.
Jon Galloway provides a decent tutorial on how to do this.
a source to share
Skipping the wrong practice of storing passwords in a text file (especially if it is not encrypted), you will need to find some kind of file format.
The simplest file could be as the ini file you are reading:
[users]
username1=password1
username2=password2
Your algorithm will look for a header [users]
, then read each line, split the line by an equal sign, and compare the information, and keep reading until you find a match, end of file, or possibly another section.
I'm not sure if you've ever worked with user authentication, but it is considered bad practice to store passwords in plain text because of a serious security issue if compromised. Typically you want to use a one-way hash (like SHA-1 or SHA-256) to hash the user's password (possibly with a known salt) and send it to your application and store that instead. This way, you never know the actual password, even if you are compromised in some way.
a source to share