Encrypt Existing SQL Server Values Using MVC 4 Default Password Encryption RRS feed

  • Question

  • User1429525508 posted

    I created a new MVC 4 project and modified the connectionString slightly to point to a different db table. When I Register a new user the code below uses my existing UserTable and appears to creates 4 additional tables, the UserTable and webpages_Membership table are the ones I am interested in.

    private class SimpleMembershipInitializer { public SimpleMembershipInitializer() { Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("DBConnectionString", "UserTable", "UserID", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } } }

    My UserTable contains 3 fields, UserID, UserName, and Password. The webpages_Membership table contains UserID, Password, it also contains other fields that I am not worried about at the moment. When I Register the new user the UserID and UserName are stored in the UserTable (Password is left blank in this table). The password is encrypted and stored in the webpages_Membership table. I went into SQL server and created some new users with UserIDs, UserNames, and Passwords(not encrypted in this table) My question is how can I use the existing MVC4 password encryption to take the un-encrypted Password from the UserTable, encrypt it and place it into the webpages_Membership table. Then I will be able to run my project and Log In using a profile that was created directly in SQL Server.

    Thursday, October 2, 2014 6:40 PM


All replies