问题描述
存储用于其他服务的密码的最安全方法是什么?
What is the safest way of storing passwords that is used to other services?
示例:
需要为其他站点存储密码以执行 rake 任务以获取需要身份验证的数据的应用程序.
App that needs to store passwords for other sites to do a rake task for fetching data that require authentication.
推荐答案
您可以将此数据存储为环境变量.例如,对于我的一个项目,我需要我的应用程序能够访问 Github 登录名.通过将以下行添加到我的 .bashrc 文件中,将此 Github 登录信息存储为环境变量.
You would store this data as environment variables. For example, for one of my projects I need my app to have access to a Github login. This Github login is stored as an environment variable by adding the following line to my .bashrc file.
export GITHUB_LOGIN=myLogin
在我的应用程序的配置文件中,我像这样引用这个环境变量:
In my app's config file I refer to this environment variable like this:
:github_login: <%= ENV['GITHUB_LOGIN'] %>
这个配置文件然后由应用程序加载,如下所示:
This config file is then loaded by the app like this:
require 'erb'
raw_data = File.read(config_file)
erbified_data = ERB.new(raw_data).result
这篇关于Rails 如何为其他服务存储密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!