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

197 views Asked by At

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'.

0

There are 0 answers