-1

I am doing log-in panel in c# form application. I do not want use database. I should take userID and password from txt file...

For example, the txt file has 5 user ID and 5 password. How can I take needing userID and password from txt?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Bub
  • 11
  • 4
  • You should show the code you have tried... You should not use a database to store passwords. Instead save to the registry and encrypt the data. – deathismyfriend Nov 24 '13 at 23:33
  • yes I have not problem about encrypt data..It's ok...only I want to learn take specific text with filestream.All example takes full file. – Bub Nov 24 '13 at 23:55

1 Answers1

0

Basic steps for reading from a file is covered in MSDN How-to guide Read From a Text File

Something like following (assuming each line contains user name and password separated by space):

var usersAndPasswords = File.ReadAllLines(@"c:\passwords.txt")
      .Select(s => s.Split())
      .Select(r => new {User = r[0], Password = r[1]);

Note: storing passwords in plain text is normally bad idea, but if you are building personal "read all my Facebook accounts" type of application it may be ok.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • the MSDN example reading full text in file. I need read specific points like mypassword and my userID.. – Bub Nov 24 '13 at 23:52
  • @akdrmrk - just add `Where` with your criteria to my sample... Also it may be better to read all file into a dictionary if you actually planning to use it as DB, otherwise all operations on file will be `O(file-length)` instead of `O(1)` for dictionary (could be fine for small files/infrequent usage). – Alexei Levenkov Nov 24 '13 at 23:55