May 2, 2007 at 3:00 pm
Hi,
I ran an update statement against a table with password = 'dba'
The weird thing was that no matter how many spaces I added in my select statement, it would still show the password..
i.e.
Update tbl_realtors
set password = 'dba'
SELECT company_name, realtor_id, first_name, last_name
FROM tbl_realtors (NOLOCK)
WHERE email = 'jean@sql.com'
AND password = 'dba '
So I updated it again, but the same thing happened.. Is this normal behavior or is there a setting/configuration I'm missing?
Thanks
Susan
May 2, 2007 at 3:03 pm
What is the datatype of the column? I'll bet it's VARCHAR. That will drop trailing blanks.
-SQLBill
May 2, 2007 at 4:37 pm
May 2, 2007 at 4:47 pm
To get exact match you mast store passwords in VARBINARY strings, not VARCHAR.
_____________
Code for TallyGenerator
May 3, 2007 at 1:17 pm
May 3, 2007 at 3:08 pm
The field is a varchar(20)
May 3, 2007 at 3:26 pm
May 3, 2007 at 3:43 pm
my bust, I read too quickly and thought the select was returning the password padded with spaces, not that you weren't getting the expected result when you padded the where clause with spaces.
to illustrate Sergiy's point
begin
declare @c1 varbinary(20),@c2 varbinary(20)
set @c1 = convert(varbinary,'dba')
set @c2 = convert(varbinary,'dba ')
if @c1 = @c2
print 'true'
if @c1 <> @c2
print 'false'
end
begin
declare @c1 varchar(20),@c2 varchar(20)
set @c1 = convert(varchar,'dba')
set @c2 = convert(varchar,'dba ')
if @c1 = @c2
print 'true'
if @c1 <> @c2
print 'false'
end
May 4, 2007 at 7:08 am
Besides the fact that passwords are stored as human readable text, could someone explain why it is better to store passwords in VARBINARY versus VARCHAR?
May 4, 2007 at 8:07 am
- uncertain matching (see initial post)
- collation dependency
VARBINARY passwords are as human readable as VARCHAR. Just need to use simple CONVERT function.
Encrypting of passwords is a subject for another discussion.
_____________
Code for TallyGenerator
May 7, 2007 at 11:13 am
May 7, 2007 at 8:31 pm
I think you mean that trailing spaces are neglected...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply