asp.net - Compare password of webpages_membership in SQL Server query -
i have web application done in asp.net mvc 4. has users, stored in sql server database in tables webpages_userprofile
, webpages_membership
, etc.
i have application, , need query table webpages_membership
, password of users stored encrypted, , compare them plain text password.
so tried doing
select * webpages_membership pwdcompare('mypasswordsend', password) = 1
but doesn't works. know column nvarchar(128)
.
how can compare it?
let's @ second argument pwdcompare
(emphasis mine):
password_hash
is encryption hash of password. password_hash *varbinary(128)*.
so, if column storing password in plain text, or storing string representation of binary hash, it's not going work. should either change column correct or need convert first, e.g. check script:
select pwdencrypt(n'mypassword');
yields:
0x0200d422c0365a196e308777c96cbef3854818601ddb516cada98dbdf6a5f23922dc0fadd29b806121ea1a26aed86f57fccb4ddf98f0efbf44ca6ba864e9e58a818785fddedf
if try compare value as string, 0:
select pwdcompare(n'mypassword', n'0x0200d422c0365a196e308777c96cbef3854818601ddb516cada98dbdf6a5f23922dc0fadd29b806121ea1a26aed86f57fccb4ddf98f0efbf44ca6ba864e9e58a818785fddedf');
if try compare as varbinary value, 1:
select pwdcompare(n'mypassword', 0x0200d422c0365a196e308777c96cbef3854818601ddb516cada98dbdf6a5f23922dc0fadd29b806121ea1a26aed86f57fccb4ddf98f0efbf44ca6ba864e9e58a818785fddedf);
if can't fix table, can perform expensive explicit conversion in query every time (note trailing ,1
important):
select pwdcompare(n'mypassword', convert(varbinary(128), n'0x0200d422c0365a196e308777c96cbef3854818601ddb516cada98dbdf6a5f23922dc0fadd29b806121ea1a26aed86f57fccb4ddf98f0efbf44ca6ba864e9e58a818785fddedf' , 1));
Comments
Post a Comment