0

I'm developing a web app for internal file sharing and one of the requirements is to have PIN code protected folders.

What I came up now is a folder like structure with the following:

  • Folder without PIN code entry - only Open button which directly forwards to the folder
  • Folder with PIN code entry - text field with Verify button which forwards only when the PIN is correct

What I'm not sure is what would be the best practice in the case of the folder with PIN code in terms of PIN verification and forwarding user to the folder. At the moment I have a web service to which I forward PIN, folder ID and user ID, all in cleartext format and I'm waiting for the service response which can either be true or false.

I'm assuming that this isn't the best practice as the smart but naughty user could loop through all the possible combinations of the PIN code and wait which one will give him true as a response. I have to add that only authenticated users can access folders so in worst case I'd know with whose user the breach was made.

What should I do to improve security and is there something I could do better?

3
  • Why PINs instead of some kind of ACL? Password sharing isn't exactly good practice. Commented Jul 22, 2015 at 8:54
  • @CodesInChaos There already is ACL, in this case PIN is additional security layer. Commented Jul 22, 2015 at 8:55
  • 1
    This question might be a better fit for Security.SE
    – JDT
    Commented Jul 22, 2015 at 9:34

1 Answer 1

1

I'm assuming that this isn't the best practice as the smart but naughty user could loop through all the possible combinations of the PIN code and wait which one will give him true as a response.

This is called a "brute-force" attack. In principle, it is impossible to prevent brute-force attacks. There is simply no way to set up a password scheme that does not allow people to try entering random passwords and see what happens. But you can make it ridiculously hard for someone to work out what anyone else's password is.

This Security.SE answer is the ultimate introduction on how to securely store user passwords, and these PIN numbers are essentially per-folder passwords. I'll try to give you a quick summary of the key points here.

When we talk about storing user passwords in a "cryptographically secure" way, the goals we usually have in mind are:

  1. Making a brute force attack as hard as possible without unduly inconveniencing legitimate users.
  2. Making sure there is no "shortcut", i.e. no attack that's more effective than brute force.

I don't know how far you want to go with security for per-folder PINs, but the concrete measures you can take basically amount to:

  • If a user enters too many invalid PIN numbers in a row, do not allow any additional attempts for a while. This is a very easy way of preventing the simplest brute force attacks.
  • Require longer PIN numbers. Obviously, if you only have four digit PINs, there simply aren't that many different numbers to try, and it's unlikely the rest of the measures on this list would help much with that.
  • Next, do not store the actual PIN numbers anywhere. Instead, whenever the user enters a PIN, run it through a tried-and-true password hashing function (PBKDF2, bcrypt or scrypt) on the server, and store only the hash. If someone ever gets access to your database, this ensures they can't simply look up everyone's PIN numbers, or easily derive the PIN numbers from the PIN hashes.
  • Then, configure the hashing function to be as slow as possible without inconveniencing your users. The idea is that trying a single password should take half a second rather than a millisecond. Then, if someone manages to dump your database and tries a brute force attack directly on the data (where you have no way of locking them out after too many failures), it will take them an impossibly long time to try every password.
  • Finally, add "salts" into the process to combat rainbow tables. I highly doubt you want to go this far, so I won't bother explaining that one.

I suspect that for PIN numbers, the first two steps might be enough for you, but the rest would still improve security. And for real user account passwords, please do go all the way.

Of course, this only deals with the most common threats that we want to protect passwords against. It doesn't do anything about man in the middle attacks or social engineering, for instance. But it probably covers the cases you're worried about.

2
  • Thank you, that's exactly the answer I was looking for, I think I'm covered then. PINs are already hashed and peppered (not salted though), files within the folders are already encrypted. What I like about your suggestion is that stupid simple idea of making hashing function as slow as possible. Thank you once again for detailed and concise answer! Commented Jul 22, 2015 at 9:59
  • @Agramer Glad I could help. Incidentally, I ignored the question of how your user authentication mechanism plays into all this, but you should probably make sure that, among other things, no one can ask for the contents of a folder without being authenticated, even with the right PIN.
    – Ixrec
    Commented Jul 22, 2015 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.