I have a scenario where I have to keep track of users last three passwords,
if the new password entered by user matches with the last three passwords in the PasswordHistory Table then I will display message to user that "you can not repeat any of your last three passwords.."
Basically I can do : select top 3 passwords from MyTable order by createdDate desc
But how to do comparision ?
I was googling for if anything like array exist in sql server 2000?
Please suggest, any pointer......
Thanks
You can use the IN keyword to see if a scalar value is within a set of values.
Here's how I would do this. I'd have a stored procedure that accepts the @.NewPassword and @.UserID as input parameters and then returns either a 1 or a 0, and in .NET code I'd do an ExecuteScalar() and cast the result to a Boolean.
The T-SQL in the stored procedure would look something like:
IF @.NewPassword IN (SELECT TOP 3 Passwords FROM PasswordHistory WHERE UserID = @.UserID ORDER BY CreatedDate DESC)
SELECT 1
ELSE
SELECT 0
|||
Hi Scott,
Thanks for your reply, its surely something which i wanted , let me try it .
will let you know how it works out.
|||
It does work !!
Thanks a lot for your time.
|||gridview:
It does work !!
Thanks a lot for your time.
Great! Happy Programming!
gridview:
It does work !!
Thanks a lot for your time.
Great! Happy Programming!
No comments:
Post a Comment