My config has Connection string with encrypted password. Code is using Entity Framework System.Data.Entity.DbContext where it holds encrypted password.
How can I customize System.Data.Entity.DbContext.Database.Connection.ConnectionString to use decrypted password.
Below code DrcMaster is throwing an erro :Login failed ( as its trying to use encrypted password)
using System;
using System.Data.Entity;
using System.Configuration;
namespace DrcAuthentication.Database.User {
public class UserContext : DbContext
{
public UserContext()
{
System.Data.SqlClient.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["UserContext"].ConnectionString.ToString());
csb.Password = EncryptionUtils.Decrypt(csb.Password);
string myCs = csb.ToString();
Database.Connection.ConnectionString = myCs;
//db.Database.Connection.ConnectionString = myCs;
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
public DbSet<DrcAuthentication.DrcMaster> DrcMasters { get; set; }
public DbSet<DrcAuthentication.AuthenticatedUser> Users { get; set; }
public DbSet<DrcAuthentication.UserRole> UserRoles { get; set; }
//public IDbSet<SuperSecured> SuperSecured { get; set; }
}
}
myCscontain a valid connection string?