here is my sp
create proc [login]
(
@.email as varchar(200)
@.password as varchar(200)
)
as
begin
select customerid from customerlogin
where email = @.email
and password = @.password
End
print 'Welcome'
print (@.email)
End
This works fine, but if the email is wrong, what do I need to add to this to print that the email is wrong and not print 'welcome email'
Help, please.....
Hello,
I think what you want is:
create proc [login]
(
@.email as varchar(200)
@.password as varchar(200)
)
as
IF EXISTS (select customerid from customerlogin where email = @.email and password = @.password)
BEGIN
print 'Welcome'
print (@.email)
END
ELSE
BEGIN
print 'Bad login!'
print (@.email)
END
GO
As a side note, best practice is to NOT pass the users' password, but rather store a hash of the password and then when the user attempts to login, you simply create a hash of the entered password and compare it with the hashed value stored in the db.
Cheers
Rob
|||create procedure sp_login
@.email as varchar(200)
@.password as varchar(200)
AS
Select CASE WHEN ((Select COUNT(*) from customerlogin where email = @.email and password = @.password) = 0)
THEN Print 'Invalid Login'
ELSE Print 'Welcome ' + @.email
END AS [EmailTest]
Adamus
 
No comments:
Post a Comment