verwendetes Datenbanksystem: <Microsoft SQL Server>
Hallo zusammen
Ich verbinde per ADO.NET mit dem Assistenten auf meine mssql DB.
Der ConnectionString ist in der App.Config.
Beim Assistent kann ich "Nein, sensible Daten aus der Verbindungszeichenfolge aussschliessen. Ich lege sie in meinem Anwendungscode fest." auswählen. Die Frage ist nur, wie lege ich das Pw in meinem Code ab?
Kann mir wer in einem Code Beispiel sagen, wie ich das Passwort im Code hinterlegen kann?
Vielen Dank
Absolut sicher gegen auslesen? Gar nicht.
Wenn halbwegs "sicher" dann da schauen [FAQ] DB-Password/Kennwort/Connection-String sicher speichern
Nein muss nicht sicher gegen auslesen sein, nur nicht ganz so offensichtlich wie direkt im app.config.
Mir reicht eigentlich wenn das Passwort klar im Code ist.
Gruss
Hallo rasemaier,
dann verstehe ich die Frage nicht ganz. Was spricht gegen eine Klasse aus der du die Sachen lesen kannst?
Gruss
Coffeebean
Microsoft MVP // Me // Blog // GitHub // @Egghead // All my talks // Speakerdeck
Hallo
Mein ConnectionString soll in der App.config bleiben, aber ohne Passwort.
Das will ich im Code setzen, aber ich weis nicht wie.
Gruss
Hallo rasemaier,
Console.WriteLine($"ThisIsMyConnectionStringWithMy{Password}");
String interpolation. Meinst du sowas?
Gruss
Coffeebean
Microsoft MVP // Me // Blog // GitHub // @Egghead // All my talks // Speakerdeck
app.config
<connectionStrings>
<add name="TestEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=testserver;initial catalog=testDB;persist security info=True;user id=TestUser;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Diesem String aus der app.config möchte ich das Password beim Programm Start mitgeben.
Die Frage ist nur wie..? Geht das ihrgend wie mit SqlConnection?
Safe storage of app secrets during development
Ist aber mit einigen älteren Technologien nicht kompatibel. Da bleibt nur: selbst eine Verschlüsselung schreiben.
Oder:
Securing Connection Strings - Avoiding Security Vulnerabilities
Ebenso unterstützt die .NET Konfiguration Verschlüsselung.
Mir reicht eigentlich wenn das Passwort klar im Code ist.
Passwörter schreibt man niemals in den Code. Abgesehen von der Sicherheit müsstest Du bei einer Passwortänderung die Anwendung neu kompilieren und neu ausrollen.
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code
Das hier kenn ich schon, aber das Problem ist, dass ich nichts installieren will.
Bzw. Meine exe und die app.config liegen auf dem gleichen Pfad. Und wenn ich diesen Code verwende, dann ist der ConnectionString erst verschlüsselt wenn der User das Programm das erste mal gestartet hat.
// Open the configuration file and retrieve the connectionStrings section.
configuration = ConfigurationManager.OpenExeConfiguration(fileName);
ConnectionStringsSection configSection = configuration.GetSection("connectionStrings") as ConnectionStringsSection;
if ((!(configSection.ElementInformation.IsLocked)) && (!(configSection.SectionInformation.IsLocked)))
{
if (encrypt && !configSection.SectionInformation.IsProtected)
{
//this line will encrypt the file
//configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
if (!encrypt && configSection.SectionInformation.IsProtected)//encrypt is true so encrypt
{
//this line will decrypt the file.
configSection.SectionInformation.UnprotectSection();
}
//re-save the configuration file section
configSection.SectionInformation.ForceSave = true;
// Save the current configuration
configuration.Save();
//configFile.FilePath
}
Kann ich mit dem einen bereits bestehenden ConnectionString aus der app.config anpassen?
Warum liest du dir die Dokumentation im verlinkten Artikel nicht durch?
Schau dir mal den Constructor an.