I have a simple table for testing HASH PASSWORDS
i have 2 columns PWD & HASHED_PWD. let's say in PWD i have password '111' in HASHED_PWD I used this query to add hashed password '111':
declare @hashThis nvarchar(150);
select @hashThis = CONVERT(nvarchar(150),(SELECT PWD FROM Customers where CustomerID='cust-111'));
update Customers set HASHED_PWD=HASHBYTES('md5',@hashThis) where CustomerID='cust-111';
the result is this:
칮핏섛鐓鈦絣䮝ຆ
but when i use the variable to hash '111':
declare @hashThis nvarchar(150);
select @hashThis = CONVERT(nvarchar(150),(SELECT PWD FROM Customers where CustomerID='cust-111'));
--update Customers set HASHED_PWD=HASHBYTES('md5',@hashThis) where CustomerID='cust-111';
select HASHBYTES('md5',@hashThis) as HASHES;
the same query but the result is different. my variable @hashThis
is:
0x6ECE4FD51BC113942692637D9D4B860E
my column data type and variable are the same nvarchar(150)
why i have different results?
any ideas?
I used this query to compare and the result is always not correct
declare @pwd nvarchar(150);
declare @pwd2 nvarchar(150);
set @pwd=HASHBYTES('md5','111');
set @pwd2=(select HASHED_PWD from Customers where CustomerID='cust-111')
if @pwd=@pwd2
print 'Correct'
else
print 'not correct'