Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have table 'login(username,password,designation)'.
I want to create stroed procedure to login.I have c# code for that but I want stored procedure from stored procedure I want to return designation.

c# code is following...
C#
string s = "select UserName,Password,Designation from Login where UserName=@uname and  Password=@pass";
               SqlCommand cmd1 = new SqlCommand(s, con);
               cmd1.Parameters.AddWithValue("@uname", TextBox1.Text);
               cmd1.Parameters.AddWithValue("@pass", TextBox2.Text);
               SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);
Posted
Updated 30-Mar-17 10:39am
v2

Hi ,
Try this
SQL
CREATE PROCEDURE usp_Login
(
@uname NVARCHAR(50),  @pass NVARCHAR(50)
)
AS
BEGIN
SET NOCOUNT ON;
SELECT  UserName,[Password],Designation
FROM dbo.Login
WHEREUserName=@uname AND [Password]=@pass
end


Best Regards
M.Mitwalli
 
Share this answer
 
 
Share this answer
 
Hi,

Sample one[^]

Sample two[^]

Use the following Query in stored procedure
SQL
select @INtegerVariable = count(UserName) from Login where UserName=@uname and  Password=@pass


then
SQL
Select @INtegerVariable
....

If the value of @INtegerVariable is 1 then login is successful, else no.

Regards
Sebastian
 
Share this answer
 
select * from UserMstr where Password=@Password and Password in (select password from UserMstr where UserName=@Username and IsDeleted='False' and IsActive='True')    and UserName=@Username      


This helps you to check sql injection also. Other wise in your query it is easy to pass your login checking with proper sql injecion.
 
Share this answer
 
/* This stored procedure should work for Oracle DB.
I am assuming the UserName column in the table is unique field
I also hope you are aware of calling stored procedure from .NET code
*/

SQL
create or replace procedure sp_login
(
p_user_name Login.UserName%type,
p_password  Login.Password%type,
p_message out varchar2
)is

v_user_count number(1):=0

begin

   if p_username='' or p_password='' then
      p_message='Username Or Password Cannot Be Blank';
   end if;

   begin
          select count(*) into v_user_count from <login> where Username=p_user_name and   Password=p_password;        
      exception
            when others then
              raise_application_error('-20001','Error While Retrieving Data.');
   end;

   if v_user_count=0 then
         p_message:='Invalid Login Details';
   elsif v_user_count=1 then
         p_message:='Success';
   else
         p_message:='Critical Error.';
   end if;

end;
 
Share this answer
 
v4
SQL
CREATE PROCEDURE login
(
	@username varchar(100)='',
	@password varchar(100)=''
)
As
Begin
	if exists(select 1 from Login where where UserName=@username and  Password=@password) 
	Begin
		Select UserName,Password,Designation from Login where UserName=@username and  Password=@password 
	End
End
 
Share this answer
 

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