Why is WebSecurity ignoring my password?

时光怂恿深爱的人放手 提交于 2019-12-08 08:41:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18824141/why-is-websecurity-ignoring-my-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!