I have configured SimpleMembership
to use my own table for user data, the Occupant
table, as follows:
WebSecurity.InitializeDatabaseConnection("EstatesContext", "Occupant", "Id", "UserName", autoCreateTables: true);
And in the register event, pass data for this table like so:
WebSecurity.CreateUserAndAccount(
model.UserName,
model.Password,
propertyValues: new {
IdNumber = model.IdNumber,
Surname = model.Surname,
FirstName = model.FirstName,
Type = model.Type,
IsActive = model.IsActive,
EMailAddress = model.EmailAddress
});
When I try and register a new user, I get the following error:
Cannot insert the value NULL into column 'Password', table 'XTimeEstates.dbo.Occupant'; column does not allow nulls. INSERT fails.
Does SimpleMembership
hash and store the password passed to CreateUserAndAccount
elsewhere? Meaning I should not explicitly store any password data? Or is something else wrong?
The Simple Membership provider stores user passwords in the 'webpages_Membership' table (this is auto-generated by the framework unless disabled), so if your 'Occupant' table has a non-nullable password field you will need to pass that as an additional value in the propertyValues construct. With that said, the Password field in the Occupant table is not necessary as the Simple Membership provider takes care of that. All that is required by Simple Membership is a field to store UserId and UserName in whatever table you pass into InitializeDatabaseConnection.