使用具有每个电子邮件和密码的不同表进行登录验证 [英] Login validation by using different tables having each email and password
问题描述
我有4个表学生,tpo,admin,campany,每个表都有一个coloumn电子邮件和密码,当用户在登录页面输入值时,即电子邮件文本和密码文本然后验证查询检查所有表和表有适当的电子邮件和密码可登录,但如果登录凭证属于tpo,则可以显示tpo页面,如果登录凭证属于学生,则可以出现其他过程可以同样的方式完成。我的表格代码是asp.net,后面是c#。
提前感谢。
我的尝试:
i通过在登录页面使用下拉列表编写代码,但是我不希望选择下拉菜单用户只需要发送电子邮件txt和密码文本。
通过将用户名和密码传递给它来写一个存储过程
,然后它将返回表名凭证属于如下
<前la ng =SQL> 创建 过程 sp_whatever( @ username nvarchar ( 50 ), @ password nvarchar ( 50 ))
as
开始
声明 @ table nvarchar ( 20 )
如果 存在(选择 top 1 * 来自学生其中 [username] = @ username 和 [密码] = @ password )
set @ table = ' student'
else 如果 存在(选择 top 1 * 来自 tpo 其中 [username] = @ username 和 [密码] = @ password )
set @ table = ' tpo'
其他 如果 exi sts (选择 top 1 * 来自 admin 其中 [username] = @ username 和 [密码] = @ password )
设置 @ table = ' admin'
其他 如果 存在(选择 top 1 * 来自 campany 其中 [username] = @ username 和 [密码] = @ password )
set @ table = campany'
else
set @ table = ' 无效'
选择 @ table
end
基于上述结果存储过程,您应将用户重定向到相关页面。我希望您知道使用Ado.net
从SP获取值。
如果多个表中存在相同的用户信用,请注意您要授权用户的顺序。
I have 4 Tables student,tpo,admin,campany and each table having a coloumn email and password when user entered a values in login page i.e email text and password text then validation query check all tables and table having proper email and password can be login but if login credential belongs to tpo then tpo page can be appear and if login credential belong to student the student from can be appear other process can be done in same way.My form code is asp.net and backed is c#.
thanks in advance.
What I have tried:
i write a code by using dropdown at login page this works but i don't want a dropdown menu for selection a user i need just email txt and password text.
Write aStored procedure
by passing the username and password to it, which in turn it will return the table name of the credentials belongs to as below
create procedure sp_whatever ( @username nvarchar(50) , @password nvarchar(50) ) as begin declare @table nvarchar(20) if exists (select top 1 * from student where [username] = @username and [password] = @password ) set @table = 'student' else if exists (select top 1 * from tpo where [username] = @username and [password] = @password ) set @table = 'tpo' else if exists (select top 1 * from admin where [username] = @username and [password] = @password ) set @table = 'admin' else if exists (select top 1 * from campany where [username] = @username and [password] = @password ) set @table = 'campany' else set @table = 'invalid' select @table end
based on the above result from the Stored proc, you shall redirect the user to the relevant page. I hope you are aware of getting the values from SP usingAdo.net
.
Take care of the order in which you want to authorize the user, if the same user cred is present in multiple tables.
这篇关于使用具有每个电子邮件和密码的不同表进行登录验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!