Hi..
I want to form a query in SQL.
My Requirement is-
I have a table - (Table Name - Users)
ID
| UserName
| Password
| EncryptedPassword
| Location
| IsActive
|
1
| abc
| abc
| 0x7890000
| US
| 1
|
2
| def
| def
| 0x88776655
| UK
| 1
|
3
| ghi
| ghi
| 0x1122334455
| India
| 1
|
4
| jkl
| jkl
| 0x987654321234
| Australia
| 1
|
In EncryptedPassword field, for inserting data, I am passing PWDENCRYPT(@Password).
This has some varbinary values.
I want to fire a select query for checking whether the username and password are correct or not.
My query is-
select Username, PWDCOMPARE(Password, PWDENCRYPT(EncryptPassword)) PasswordCompare, Location from Users where IsActive=1
Here, even if I pass correct password, I get the PasswordCompare field as 0.
How to encrypt and decrypt passwords in SQL Server??
Please help.