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

  • Home
  • SEARCH
  • 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 241425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:45:09+00:00 2026-05-11T20:45:09+00:00

I thought that I should use JSON for ID/pass storing format once, but I

  • 0

I thought that I should use JSON for ID/pass storing format once, but I reserched about it, then I finally found that JSON is too difiicult to me, so now I am considering to use CSV.

The CSV file would be like this. File name is id.csv.

aaa_id,aaa_pass
bbb_id,bbb_pass
ccc_id,ccc_pass

Left colum is id, and right colum is password and each infos are separated by commas. Login form is login.php. This is my sample for login.php.

<form method="post" action="login-process.php">
id <input type="text" name="id" size="20"><br>
pass <input type="text" name="pass" size="20"><br>
<input type="submit" value="login">
</form>

And now I need to write login-process.php

<?php

error_reporting(0);

$handle = fopen("id.csv", "r");
while (($data = fgetcsv($handle)) !== FALSE) {
    print $data['0'];
    print "=>";
    print $data['1'];
    print "<br>";
}
?> 

When I excute this script, it shows as:

aaa_id=>aaa_pass
bbb_id=>bbb_pass
ccc_id=>ccc_pass

I feel I am closing to final goal, but I need to write authenticate code.

How do I improvement of this code?

  • 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-11T20:45:09+00:00Added an answer on May 11, 2026 at 8:45 pm

    Firstly, I agree with what Paolo says, this is definately the wrong approach. In addition to what he said:

    • The login process will get slower and
      slower as you have more users in the
      file (this will probably be true to an extent for any system, but I think it will be significant here)
    • Making changes in the middle of the
      file will be a complete pain
    • Having
      multiple script instances trying
      write to the file simultaneously will
      probably result in corruption/missing
      data

    However, if you were to have a form with fields called ‘username’ and ‘password’, you could process it like below. I am debating whether I should remove the code in order to avoid the risk of people actually writing stuff like this.

    <?php
    
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    
    if (!strlen($username) || !strlen($password)) {
        die('Please enter a username and password');
    }
    
    $success = false;
    
    $handle = fopen("test.csv", "r");
    
    while (($data = fgetcsv($handle)) !== FALSE) {
        if ($data[0] == $username && $data[1] == $password) {
            $success = true;
            break;
        }
    }
    
    fclose($handle);
    
    if ($success) {
        // they logged in ok
    } else {
        // login failed
    }
    

    You probably will want to read up on using Sessions to remember that the user is logged in across multiple page requests.

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

Sidebar

Related Questions

I have read that you should not use get json for retrieving sensitive data
Should be an easy one. I thought, from reading this blog post that I
I thought that calling BeginInvoke more than once on the same delegate instance would
I thought that layout is just a widget that keeps more widgets inside. But
At first, I thought this should be very easy. Just use $(selector).val() to get
I'm about to write a MMO, using HTTP-requests that are responsed with JSON. I
I thought that a delegate instance was interchangeable with a function instance. Take the
I thought that by default my Regex would exhibit the greedy behavior that I
I thought that this was easier… I have a asp:hyperlink control, with target=_blank ,
I thought that in principle Haskell's type system would forbid calls to impure functions

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.