Click here to Skip to main content
14,550,977 members
Rate this:
Please Sign up or sign in to 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...
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
Rate this:
Please Sign up or sign in to vote.

Solution 4

Hi ,
Try this
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
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,

Sample one[^]

Sample two[^]

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


then
Select @INtegerVariable
....

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

Regards
Sebastian
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

/* 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
*/

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;
   
v4
Rate this:
Please Sign up or sign in to vote.

Solution 7

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
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100