比将mysql密码以纯文本格式存储在配置文件中更好的方法? [英] a better approach than storing mysql password in plain text in config file?

查看:84
本文介绍了比将mysql密码以纯文本格式存储在配置文件中更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令我感到困扰的是,许多PHP程序要求用户将mysql密码以纯文本(字符串或常量)存储在应用程序根目录下的配置文件中.

It's always bothered me that many PHP programs require the user to store the mysql password in plain text (in a string or constant) in a configuration file in the application's root.

这些年来,有没有更好的方法呢?

Is there any better approach to this after all these years?

到目前为止,我提出了两个最小的安全性增强措施:

So far I have come up with two minimal security boosts:

  1. 使用.htaccess中的规则通过网络使文件不可读 (以防php失败或存在读取php源代码的安全漏洞)

  1. make the file unreadable via the web using rules in .htaccess (in case php fails or there's a security vulnerability to read php source)

在建立数据库连接后销毁内存中的密码(未设置) (以防止由于安全漏洞,注入等导致字符串转储)

destroy the password in memory after the db connect is made (unset) (to prevent string dumps from a security breach, injection, etc.)

但是,当然,这些解决方案都不能解决原始问题.

but of course neither of those solve the original problem.

感谢其他任何想法!

推荐答案

由于您的代码将需要密码,因此没有完美的安全性.但是您很难恢复.

Since your code will need the password there is no perfect security. But you can make it hard to recover.

我在我的Web配置中放入了一些哈希,作为环境变量,例如MYSQL_PASS_HASH

I put some hash in my web config, as an environment variable, say MYSQL_PASS_HASH

然后我做类似md5(getenv('MYSQL_PASS_HASH').'gibberish$qwefsdf')的操作,然后输入密码.如果您偏执,当然应该在unsetenv之后.

Then I do something like md5(getenv('MYSQL_PASS_HASH').'gibberish$qwefsdf') which is then the password. Of course you should unsetenv after that if you're paranoid.

您的密码实际上不会存储在某个地方,只有当有人同时拥有您的Web配置您的数据库包括时,才能恢复该密码.

Your password will not literally be stored somewhere, and it can be recovered only when someone has both you web config and your database include.

这发生在webroot之外的文件中(不要完全信任.htaccess).

This happens in a file outside of the webroot (don't put all your trust in .htaccess).

这篇关于比将mysql密码以纯文本格式存储在配置文件中更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆