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

问题描述 投票:3回答:1

虽然调试我目前有

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

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

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

c# git passwords
1个回答
4
投票

好的做法是将它保存在您添加到.gitignore的秘密配置文件中

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

<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>
© www.soinside.com 2019 - 2024. All rights reserved.