10/02/2013
how to check when username and password both are wrong or correct in SQL
DECLARE @UserName VARCHAR(250) = 'Softmith'
DECLARE @PASSWORD VARCHAR(250) = 's1UYEvirCgDxBP1eo1T4aw==1'
DECLARE @UserStatus VARCHAR(250)
DECLARE @PasswordStatus VARCHAR(250)
SET @UserStatus = CASE WHEN EXISTS (SELECT USERNAME FROM Users WHERE USERNAME=@UserName ) THEN 'UserName' END ;
IF @UserStatus IS NULL
BEGIN
SET @PasswordStatus = CASE WHEN EXISTS (SELECT PASSWORD FROM Users WHERE PASSWORD = @PASSWORD ) THEN 'Password' END;
IF @PasswordStatus IS NULL
BEGIN
SELECT 'USER NAME AND PASSWORD ARE DOES NOT EXIST' AS UserStatus
RETURN
END
ELSE
BEGIN
SELECT 'USER NAME DOES NOT EXISTS' AS UserStatus
RETURN
END
RETURN
END
ELSE
BEGIN
SET @PasswordStatus = CASE WHEN EXISTS (SELECT PASSWORD FROM Users WHERE USERNAME=@UserName AND PASSWORD = @PASSWORD ) THEN 'Password' END;
IF @PasswordStatus IS NULL
BEGIN
SELECT 'PASSWORD IS WRONG' AS UserStatus
RETURN
END
ELSE
BEGIN
SELECT
USERNAME,
PASSWORD,
USERID,
'Success' as UserStatus
FROM
Users
WHERE
USERNAME = @UserName AND PASSWORD = @PASSWORD
END
END
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment