如何在文件中安全地存储密码?
我的程序需要密码才能打开某些功能。密码可由管理员设置。我的应用程序将密码存储在文件中。但是,如果文件被删除或损坏,应用程序就会丢失密码。另一种情况是,如果该文件被替换为原始文件,则密码将为空。关于在文件中存储密码有什么建议吗?
编辑: 我的应用程序有一个功能。该功能受管理员(PC 所有者)设置的密码保护。访客应输入密码才能禁用该功能。 操作系统:Windows
My program requires password to open some features. The password can be set by an administrator. My app stores the password in a file. But, if the file was deleted or damaged, the app loose the password. Another scenario is if the file was replaced with original file then the password will be empty. Any suggestions about storing a password in a file?
edited :
My app has a feature. The feature is protected by a password that can be set by a admin (owner of the PC). Guest should enter password to disable that feature.
OS : Windows
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法保护文件不被删除。在这种情况下,只是不允许任何用户登录您的应用程序(如果密码为空,同样适用)。
如果您将密码存储在文件中(或任何地方),您应该对它们进行哈希处理(例如使用 md5 或 sha1)。所以它们不能以纯文本形式读取。要在登录期间检查密码,只需执行以下操作(php 中的基本示例):
You can't protect the file from being deleted. In that case just don't allow any user to log in to your application (same applies if the password is empty).
If you store passwords in a file (or anywhere really) you should hash them (e.g. using md5 or sha1). So they can't be read in plaintext. To check the password during login just do (basic example in php):
什么样的节目?哪个平台? Windows、Mac、Linux、安卓?
文件总是可以以一种或另一种方式被删除或替换。您可以将其放在“更安全”的地方,用户无法轻松找到它,但这取决于平台。
What kind of program ? Which platform ? Windows, mac, linux, android ?
Files can always be deleted or replaced, one way or another. You can put it somewhere "safer" where the user can't find it easily, but if depends of the platform.