Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7552153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:41:18+00:00 2026-05-30T10:41:18+00:00

For just some fun i am trying to use Flat File databases to read

  • 0

For just some fun i am trying to use Flat File databases to read some data.The file used is text file and plain text format. I did design it such that there is format of storing the data for example a user record like below.

stackoverflow | 12345 | 12/12/2012 12:12:12 AM

where the above data if of format username | password | lastlogin. I am thinking of what are the ways i can validate a user using username, password and if found update the last login date and save the file without a exception(other users will also be using same file)

Could you explain with a code how to update last logindate when login successfull & how to validate username password.

I am using C#, .NET 2.0..

Right now psedocode is like below;

File read DB.txt
      When text not empty
            split text in file with \n as separator character
            For each item in the output array split using pipe symbol
            check if [0] and [1] index match with username & password supplied
               if matched
                    How to update and save
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:41:19+00:00Added an answer on May 30, 2026 at 10:41 am

    If performance is no problem, you should rebuild the file by moving every record coming after the record you want to update up or down depending on the number of bytes added/removed due to the update operation. Something like:

    public void UpdateRecordTest()
    {
        string changedRecord =
            string.Format("{0}|{1}|{2}", UserName, Password, LoginDate);
    
        // get a copy of the new records in bytes. This varies based on the encoding
        byte[]changedRecordBytes;
        using(MemoryStream tempStream = new MemoryStream())
            using(StreamWriter tempWriter =
              new StreamWriter(tempStream, Encoding)) {
            tempWriter.WriteLine(changedRecord);
            changedRecordBytes = tempStream.ToArray();
        }
    
        using(MemoryStream tempStream = new MemoryStream) {
            // save the rest of the file in memory. When the file itself gets too big
            // you want to buffer this in a recursive manner (last part first)
            CurrentStream.CopyTo(tempStream);
    
            // adjust the position to move to the start of the current record
            CurrentStream.Position -= CurrentRecordBytes.Length;
    
            // write the temp data
            CurrentStream.WriteTo(changedRecordBytes);
    
            // copy the rest of the data
            tempStream.CopyTo(CurrentStream);
        }
    }
    

    If performance is a problem, you might want to 0 out the current record and rewrite it at the end of the file thereby creating gaps but ensuring that no data has to be moved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I am just trying to learn some of this fun stuff now,
I'm writing some code (just for fun so far) in Python that will store
I built (just for fun) 3 classes to help me log some events in
Just some background, sorry so long winded. I'm using the System.Data.SQLite ADO.net adapter to
I'm creating an asp.net app with just some lite data access from xml files.
I'm having some fun trying to pick a decent SQL Server 2008 spatial index
I am trying to have some fun in summer. Writing a piece of code
I am playing around some in C++, just for fun. I have just begun
I have some tests that use guids. The guids used don't need to be
I'm having some fun trying to get my head around some MVP stuf, as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.