Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server checksum in EF

I have a table in SQL Server like this :

Users :

int ID PK Identity
nvarchar(50) Username
nvarchar(50) Password

I stored the checksum string in the Password column and use this method to hash password and the stored them in my table

Now I want to use this table in EF like this ;

User = DBContext.Users.SingleOrDefault(rec => rec.Username == Request["U"] && rec.Password == Request["P"]);

but because I stored the checksum values in my table, so I must to change Request["P"] to use it in EF

Sorry I am new in English, did you find out what it I talking about it ? (I hope I could explain my problem clearly :( )

UPDATE1 : If I have a query like this :

Select * from Users where username = @p1 and password = checksum(@p2)

how I convert @p2 to use that query like this :

Select * from Users where username = @p1 and password = @p2 --Checksum omitted
like image 965
Ali Foroughi Avatar asked Nov 21 '25 11:11

Ali Foroughi


1 Answers

So long as you're using Database First (this means that you have EDMX), you can add custom function like this:

SELECT CHECKSUM(@password)

to you EDMX, and then you may call it to calculate checksum value for the password before using password in a LINQ query.

like image 93
Dennis Avatar answered Nov 23 '25 23:11

Dennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!