Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to create login procedure based on roleid from multiple table

I have two table with me
table-1 tblTeacher
----------------------------------------------------
Id Name Email Password RoleId Status
----------------------------------------------------
1 aaa aaaa 123 1 0
2 bbb bbbb 1234 2 1
3 ccc cccc 1234 1 1

table-2 tblStudent
----------------------------------------------------
Id Name Email Password RoleId Status
----------------------------------------------------
1 xxx xxxx 123 3 1
2 yyy yyyy 1234 3 0


i want to login based on the role id and if status is true(1)

What I have tried:

SQL
create procedure spLoginn(
@Email varchar(50),
@Pasword varchar(20),
@RId int out
)
as begin
  --declare @Rid int
  if @Email is not null
     if @Pasword is not null
	   set @Rid=(Select RoleId from tblTeacher where Email=@Email and Pasword=@Pasword)
	 if @Rid=0
	   set @Rid=(Select RoleId from tblStudent where Email=@Email and Pasword=@Pasword)
	   end
Posted
Updated 27-Sep-17 0:06am
v2
Comments
Richard Deeming 27-Sep-17 12:15pm    
I appreciate this is probably just a school project, but in any real-world application, you should NEVER store passwords in plain text.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

1 solution

try

alter procedure spLoginn(
@Email varchar(50),
@Pasword varchar(20),
@RId int out
)
as BEGIN

  
  if ( @Email is not null and  @Pasword is not null ) 
		begin
			   set @Rid=(Select RoleId from tblTeacher where Email=@Email and Pasword=@Pasword)
			 if @Rid is null
			   set @Rid=(Select RoleId from tblStudent where Email=@Email and Pasword=@Pasword)
	     end
  END


if @RId is null then the Email/Password combination is not present either table.
 
Share this answer
 
Comments
Member 12611488 27-Sep-17 7:43am    
Thank You very much Karthik
it's working as aspected
Karthik_Mahalingam 27-Sep-17 7:50am    
welcome :)

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