How to parse password in varbinary from database to IdentityUser string in Web Api Authentication

天大地大妈咪最大 提交于 2019-12-11 14:43:14

问题


I have in my database a column named Password of type Varbinary(150). When I want to consult that database in the web api, for example:

var dbCon = ApplicationDbContext.Create(connectionStringUsers.ToString()); var users = dbCon.Users; var list = users.ToList(); In the last line I have this error:

The 'PasswordHash' property on 'IdentityUser'4' could not be set to a 'System.Byte[]' value. You must set this property to a non-null value of type 'System.String'.

It know that if I change my schema from type Varbinary to Varchar it is going to work. But I cant change the schema. How can I hack this parse?

Thank you

UPDATE 1

Maybe something like this:

modelBuilder.Entity<ApplicationUser>().ToTable("MyUsers", "dbo").Property(p => p.PasswordHash).HasColumnType("varbinary");

But I get this error:

error 2019: Member Mapping specified is not valid. The type 'Edm.String[Nullable=True,DefaultValue=,MaxLength=Max,Unicode=True,FixedLength=False]' of member 'PasswordHash' in type 'OhmioWEBAPI.Models.ApplicationUser' is not compatible with 'SqlServer.varbinary[Nullable=True,DefaultValue=,MaxLength=8000,FixedLength=False]' of member 'Password' in type 'CodeFirstDatabaseSchema.ApplicationUser'.

来源:https://stackoverflow.com/questions/46067447/how-to-parse-password-in-varbinary-from-database-to-identityuser-string-in-web-a

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