我有以下代码登录我的网站中的单独管理区域:
<script runat="server">
Public Sub Login(ByVal s As Object, ByVal e As EventArgs)
If UserName.Text = "admin" And Password.Text = "pw11" Then
Session("Admin") = True
Response.Redirect("default.aspx")
Else
Session("Admin") = False
LtlLogin.Text = "<p>Sorry you have provided incorrect login details.</p>"
End If
End Sub
</script>
如何拥有它,以便有另外两个或三个用户名和密码帐户登录?
提前致谢!
答案 0 :(得分:0)
Private ReadOnly _credentials = New Dictionary(Of String, String) From {
{"admin", "pw11"},
{"admin1", "pw12"},
{"admin2", "pw13"}
}
Public Sub Login(ByVal s As Object, ByVal e As EventArgs)
Dim storedPassword = ""
If _credentials.TryGetValue(UserName.Text, storedPassword) And storedPassword = Password.Text Then
Session("Admin") = True
Response.Redirect("default.aspx")
End If
Session("Admin") = False
LtlLogin.Text = "<p>Sorry you have provided incorrect login details.</p>"
End Sub