I have a .net winforms application used in LAN by the company's employees, and it should access a network share to copy files to it. The share has credentials that should not be known to end users. What is the best practice to provide the credentials when accessing the share without hard-coding or exposing them to end users?

  • 2
    Somebody should make a Clippy-esque script. "It looks like you're trying to build client software that hides secrets from its users / can be distributed but not duplicated/spoofed. Would you like some help with understanding why this can't be done?" A software client is a user agent. Everything it does, or even can do, is on behalf of the user. It is fundamentally incoherent for it to be capable of something - like using a credential - that the user is not. That hasn't stopped people from trying, but the history of attempts (most notably DRM) is a list of failures and wasted effort.
    – CBHacking
    Commented Jul 13, 2021 at 9:25
  • 1
    It would be helpful to know why you're trying to hide this credential. Why not just let people access the share under their own credentials? You can have a unique one per user, or just have the permissions on the directory set such that only a file's owner can access the file, if you're worried about cross-user access. It may be possible to solve the issue you have, even though the answer to your question is "you can't".
    – CBHacking
    Commented Jul 13, 2021 at 9:30

1 Answer 1


The best practice is not to use credentials embedded into the application.

Think of Kerckhoffs's principle: You should assume that attacker knows everything about your application. It it contains an embedded password, then you should assume the attacker knows it, too.

What can be alternatives?

A) On the share drive create a directory for each user and set permissions, so that only particular user can access it.

B) You can use PKI, or more precisely, a hybrid encryption based on PKI. Your application can encrypt files using public key before uploading them to the share. Then despite everyone can download files no one would be able to decrypt them.

  • could a third alternative be that the desktop application uploads the files by a web service which in turn copies those files to the share using the required credentials?
    – Nina
    Commented Jul 13, 2021 at 6:17
  • @Nina Sure, but anybody could upload files to that web service, and it would presumably pass them along. Maybe that's OK - you don't care who the files come from, or consider anybody with network access an authorized user - but at that point it's just a (semi-)public write-only file drop (whatever it does with the files afterward isn't relevant to the client). If that's what you want, you should have asked about that, not about hiding credentials in desktop software. (Or of course you could make the web service require authentication / authorization.)
    – CBHacking
    Commented Jul 13, 2021 at 9:35
  • @Nina: Sure, a web service could be even better. But you asked about a network share which means access on the file system level. Sure, you can use a web service. And you can use SSO with current user info to access this web service, and on the server side you can distinguish what file comes from what user.
    – mentallurg
    Commented Jul 13, 2021 at 9:41
  • @CBHacking , mentallurg : Thanks for the helpful comments. I mentioned the network share because this is literally the situation I am facing. Although it is a share, but access is not allowed for clients neither read nor write. It is allowed to a single account that I will use its credentials. That's why I asked in the first place. Now with the service option, I can embed those credentials in the service instead of the client.
    – Nina
    Commented Jul 14, 2021 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .