Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE FUNCTION `bank`.`FetchUserDetails` (parUname varchar(45), parpassword varchar(45),parusertype varchar(45))
RETURNS varchar(200)
DETERMINISTIC
BEGIN

declare varuname varchar(45);
declare varpassword varchar(45);
declare varuseType varchar(45);

select username,password,userType into varuname,varpassword,varuseType
from bank.user
where varuname = parUname and
varpassword = parpassword and
varuseType = parusertype;

RETURN varuname and varpassword and varuseType;
END

Can someone please tell me what is wrong with this sql statement?
what i am trying to do is authenticate a user based on the details provided and after authenticating return the username, password and role to the calling method.
Posted

1 solution

Well first off, you shouldn't be storing passwords in clear text - see here: Password Storage: How to do it.[^]

Other than that we would need to know what is does that it shouldn't, or doesn't do that it should.
 
Share this answer
 
Comments
Georges23 31-Oct-12 15:12pm    
its suppose to return the password, username, usertype. right now its not.
OriginalGriff 31-Oct-12 15:21pm    
So what is it returning?
Georges23 31-Oct-12 15:45pm    
its returning null when i call it
OriginalGriff 31-Oct-12 16:17pm    
The most likely cause is that it is failing one or more of the AND clauses in the WHERE statement. (Assuming you are using MySql, MsSql doesn't use that syntax)

I would try changing it to check just one field against a constant value, and then move up adding a bit at a time. It may be that the data you are seeking is not in the DB.
Georges23 31-Oct-12 16:19pm    
when i return one variable it works. you are right the "and" key cannot be used there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900