<%@ Page Language="VB" Trace="false" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load
Dim actionstr as String
If User.Identity.ISAuthenticated = "false" then
If not Request.QueryString("action") = "login" then
Response.Redirect("Corefile.aspx?action=login")
end if
end if
Trace.Write( "User.Identity.ISAuthenticated = " & User.Identity.ISAuthenticated )
End Sub
Sub Button2_Click(sender As Object, e As EventArgs)
FormsAuthentication.SignOut
Response.Redirect("Corefile.aspx?action=login")
End Sub
Function Authenticated(username As String, password As String) As Boolean
Dim dbconnection As Sqlconnection
Dim getuserID as Sqlcommand
Dim userID as SqlDataReader
dbconnection = New SqlConnection( "Server=888;uid=commline;pwd=88;database=88" )
dbconnection.open()
getuserID = New sqlcommand( "Select u_id FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(txtuser.text) & "' AND u_password = '" & Microsoft.Visualbasic.Lcase(txtpass.text) & "'", dbconnection )
userID = getuserID.ExecuteReader()
If userID.HasRows then
While userID.Read()
Return True
End While
Else
Return False
End if
userID.close()
dbconnection.close()
End Function
Sub Button1_Click(sender As Object, e As EventArgs)
If Authenticated(txtuser.text,txtpass.text) then
Dim ticket as New FormsAuthenticationTicket( txtuser.text, checkbox1.checked, 10 )
Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName,encticket))
Response.Redirect("Corefile.aspx?action=summary")
else
Label1.text = "Bad username or Password"
end if
End Sub
</script>
<% Select Case Request.QueryString("action") %><% Case "login" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<font face="Trebuchet MS" size="5"><strong>CLIENT LOGIN</strong></font>
</p>
<p>
<font size="2"><font face="Trebuchet MS">Username:</font>
<br />
</font>
<asp:TextBox id="txtuser" runat="server"></asp:TextBox>
</p>
<p>
<font face="Trebuchet MS" size="2">Password:</font>
<br />
<asp:TextBox id="txtpass" runat="server"></asp:TextBox>
</p>
<p>
<asp:CheckBox id="CheckBox1" runat="server" Text="Remember me with Cookies?"></asp:CheckBox>
<br />
<br />
<asp:Label id="Label1" runat="server" font-bold="True" forecolor="Red" font-size="X-Small" font-names="Trebuchet MS" width="227px">Welcome
to Client Login</asp:Label>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Login" Width="72px"></asp:Button>
</p>
<!-- Insert content here -->
</form>
<p>
<% Case "summary" %>
User.Identity.IsAuthenticated = <% Response.write ( User.Identity.ISAuthenticated ) %> <p>
<form runat="server">
<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Log Out" Width="72px"></asp:Button>
</form>
<% Case Else %>
What do you want?
<% End Select %>
</p>
</body>
</html>