Validation for password field

  • Hi all,

    I have a problem with the folllowing scenario that i have inserted the different password into my table but when i try to retrive the username and details for a particular user by pasword it's retriveing all three records instead of retriveing one record,Can any one help me on this

    My Query

    select * from login where pwd='Test123'

    but when i try to retrive record with username i'm getting the correct o/p

    select * from login where name='Martin' and pwd='Test123';

    Following is the script,

    --

    create table login(name varchar(20),pwd varchar(20));

    insert into login values('Martin','Test123');

    insert into login values('Ricky','test123');

    insert into login values('Watson','tesT123');

  • Chandru (10/23/2008)


    Hi all,

    I have a problem with the folllowing scenario that i have inserted the different password into my table but when i try to retrive the username and details for a particular user by pasword it's retriveing all three records instead of retriveing one record,Can any one help me on this

    My Query

    select * from login where pwd='Test123'

    but when i try to retrive record with username i'm getting the correct o/p

    select * from login where name='Martin' and pwd='Test123';

    Following is the script,

    --

    create table login(name varchar(20),pwd varchar(20));

    insert into login values('Martin','Test123');

    insert into login values('Ricky','test123');

    insert into login values('Watson','tesT123');

    For case sensitive search, use varbinary for ex:

    select * from login where Convert(varbinary(8),pwd)= convert(varbinary(8),'Test123')

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • That would mean your table have three different records with the same password. Depending on your requirement, you can setup USERNAME & PASSWORD as unique index keys.

    -- CK

  • Thanks Mr.Krayknot it worked well..

    Cheers.

  • Chandru (10/23/2008)


    Thanks Mr.Krayknot it worked well..

    Cheers.

    You are most welcome

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • Chandru (10/23/2008)


    create table login(name varchar(20),pwd varchar(20));

    insert into login values('Martin','Test123');

    insert into login values('Ricky','test123');

    insert into login values('Watson','tesT123');

    If such situation is very common, I would suggest you to look in the collation settings.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply