本文介绍了页面根据角色(char)进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助请认证请
我有这些属性的用户名(字符串),密码(字符串),名称(字符串)和角色(Char)在我的数据库中(身份验证表)
i需要一个身份验证(登录)page.as。请给我一些示例链接。
Need help please Authentication please
I have these property username(String),password(string) ,name(String) and Role(Char) in my database(Authentication table)
i need a Authentication(login) page.as per the Role. please give me some example links.
推荐答案
Sub validateuser()
Try
sqlcon = New OleDbConnection(constr)
sqlcon.Open()
sqlcmd = New OleDbCommand("SELECT COUNT(*) FROM att_userrole WHERE username = '" + Login1.UserName + " AND password = '" + Login1.Password + "'", sqlcon)
retval = sqlcmd.ExecuteScalar
If retval = 1 Then
sqlcmd = New OleDbCommand("SELECT role, emailid FROM att_userrole WHERE username = '" + Login1.UserName + "'", sqlcon)
sqlrdr = sqlcmd.ExecuteReader()
sqlrdr.Read()
Session("username") = Login1.UserName
getrole = (sqlrdr.Item("role"))
Session("userrole") = getrole
getemail = (sqlrdr.Item("emailid"))
Session("reqemailid") = getemail
Response.Redirect("~\Home.aspx")
'Response.Write("you are valid " & Session("username") & " with role " & getrole)
Else
'IF USERNAME IS INVALID
'-----YOUR CODE GOES HERE----
lbl_msg.Text = ("Invalid login attmept")
End If
Catch ex As Exception
lbl_msg.Text = ex.Message.ToString
End Try
End Sub
经过身份验证和检查后,您可以在会话中保存详细信息。然后在其他页面中查看会话值,如下所示
After authentication and checking you save the details in Sessions. Then in other pages just check the session values like the below
If Session("username") = "" Then
loggedin = 0
Response.Redirect("~\login.aspx")
Else
Master.ChangeLabel("Welcome " & Session("username") & " | " & Session("userrole") & " | ")
End If
If Session("userrole") = "Admin" Then
'You are admin and put your code here
Else
'You are guest, put your code here
End If
这篇关于页面根据角色(char)进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!