2

I have a program that hashes some passwords and saves them to .txt files, I'm not using databases for storage.

My questions is, is it considered more secure to save hashed passwords in one file or to have them separate?

Example 1

admin.txt - hashed password

user1.txt - hashed password

Example 2

Passwords.txt = admin/user1's hashed passwords on separate lines

Is one more secure than the other? The only issue with the second example is how would you determine whose password belongs to who.

I guess in my opinion I would choose the first example because that way you can also compare entered usernames so an attacker cannot just spam the password button with potential passwords.

Rodia
  • 105
  • 4
  • 3
    with #1, it might be good to salt+hash the username and name the file that (instead of the plain username) so attackers can't (as easily) get a full list of user names in a breach. it doesn't add much verification time... – dandavis Jan 03 '17 at 07:05
  • 1
    Bit of an aside, but from a developer perspective you'd probably make life a lot easier on you by using a sqlite database, OP. I mean, do what you want, but the set up isn't much longer than a .txt and it's easier to retrieve data later. – Monica Apologists Get Out Mar 30 '18 at 13:08

3 Answers3

5

Do whatever results in less / simpler code.

From a threat model perspective, if an attacker can access one file, they can access the other. You're much more likely to run into issues with logical flaws in your code, so keep the code simple and short. Pick whichever of the two choices offers you more simplicity.

Also, make sure you understand password hashing properly, and follow good practices.

Polynomial
  • 132,208
  • 43
  • 298
  • 379
2

I agree with the other answers that from a security perspective it doesn't matter which method you use. I'd like to address one of your other questions though to make sure we're on the same page:

The only issue with the second example is how would you determine whose password belongs to who.

If you use the single file method, you could do something like this:

username|salt|hashed-password
username2|different-salt|another-hashed-password
...

Note if you ever have a lot of users (say more than 100K) you may start having performance issues with both of the methods you described, and a database would probably be the better way to go.

TTT
  • 9,122
  • 4
  • 19
  • 31
0

I think there is no one method better than other for your case... in a standard scenario (all users and hashed passwords on same table in a database), so is the same risk, if is accessed, all are accesed.

If you have a flaw in your web which causes some kind of access to a file, probably is because command execution, so all files are going to be accessed.

So in my opinion you can do it on your own.

OscarAkaElvis
  • 5,185
  • 3
  • 17
  • 48