c# - 在源代码管理中存储您不想要的密码的位置

标签 c# git passwords

我目前正在调试

#if Debug
   new NetworkCredential("myUsername","myPassword", "myDomain");
#endif

一个好的解决方案是将密码存储在一个文件中,然后我读取该值(仅在调试时)。然后将该文件添加到 .gitignore?

生产环境永远不会读取此值,因为它是从已登录用户的 RestSharp 的 NtlmAuthenticator 获取的。

最佳答案

好的做法是将其保存在您添加到 .gitignore

的 secret 配置文件中

您可以使用 appSettings 中的 file 属性来实现,例如:

<appSettings file="..\..\AppSettingsSecrets.config">
    <!-- whatever keys that are kept on source control -->
</appSettings>

并在 AppSettingsSecrets.config

<appSettings>   
    <!-- SendGrid-->
    <add key="mailAccount" value="My mail account." />
    <add key="mailPassword" value="My mail password." />
    <!-- Twilio-->
    <add key="TwilioSid" value="My Twilio SID." />
    <add key="TwilioToken" value="My Twilio Token." />
    <add key="TwilioFromPhone" value="+12065551234" />

    <add key="GoogClientID" value="1.apps.googleusercontent.com" />
    <add key="GoogClientSecret" value="My Google client secret." />
</appSettings>

关于c# - 在源代码管理中存储您不想要的密码的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52151057/

相关文章:

c# - 如何在 c sharp 中的每个循环中跳过 a 中的特定位置?

svn - 我可以在 svn repos 中使用 git repos

encryption - 在 JDK 1.4 API 中,如何加密用户在文本框中输入的用户密码?

javascript - 如何使用脚本向 Firefox 中的存储添加密码?

javascript - 如何防止网站禁用表单自动完成功能?

c# - DatePickerTextBox 切换日月

c# - 无法在 Windows 10 上安装 dotnet-ef 工具

C# ASP.NET MVC : Single-Line If Clause in View?

git - 允许代理转发使用 Cmder (ConEmu)

Git 远程跟踪分支与具有不同 SHA 的相同提交的本地分支不同