ASP.NET2.0(VB)+ACCESS的自定义登陆页

通过孟繁永

ASP.NET2.0(VB)+ACCESS的自定义登陆页

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Login</title>
    <link href="Images/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 387px">
            <tr>
                <td style="width: 7px">
                    UserName</td>
                <td>
                    <asp:TextBox ID="TextBoxU" runat="server"></asp:TextBox></td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxU"
                        ErrorMessage="*"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td style="width: 7px">
                    Password</td>
                <td>
                    <asp:TextBox ID="TextBoxP" runat="server" TextMode="Password"></asp:TextBox></td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxP"
                        ErrorMessage="*"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td style="width: 7px">
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="Login" /></td>
                <td>
                    <asp:Label ID="LabelErr" runat="server"></asp:Label>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Register.aspx" Target="_self">Register</asp:HyperLink></td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

————————————————————————————————————————

Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb
Partial Class Login
    Inherits System.Web.UI.Page
    Public p As String   ‘保存密码
    Public t As Integer   ‘保存登陆尝试次数
    Public c As String    ‘保存成员资格
    Public Id As Integer

 

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        t += 1
        If t < 5 Then

            Dim ss As String
            ss = System.Configuration.ConfigurationManager.ConnectionStrings("ilaConnectionString").ConnectionString

            Dim conn As New OleDbConnection
            conn.ConnectionString = ss

            Dim cmd As New OleDbCommand
            cmd.CommandText = "SELECT [Password],[Class],[Id] FROM [User] WHERE [Name] =?"
            cmd.Connection = conn
            ‘ Create a OleDbParameter for each parameter in the stored procedure.
            Dim userNameParam As New OleDbParameter("?", TextBoxU.Text)
            cmd.Parameters.Add(userNameParam)
            Dim reader As OleDbDataReader = Nothing

            Try
                conn.Open()

                reader = cmd.ExecuteReader
                reader.Read()

                If reader.HasRows = False Then
                    reader = Nothing
                Else

                    p = reader("Password").ToString
                    c = reader("Class").ToString
                    Id = reader("Id")
                End If

            Catch ex As Exception
                Throw New Exception(ex.Message)

            Finally
                If Not (reader Is Nothing) Then
                    reader.Close()
                End If
                If Not (conn Is Nothing) Then
                    conn.Close()
                    conn.Dispose()
                    GC.SuppressFinalize(conn)
                End If
            End Try

            If p = TextBoxP.Text Then
                Session("User") = TextBoxU.Text
                Session("C") = c
                Session("Id") = Id
                Response.Redirect("Admin/Default.aspx")
            Else
                LabelErr.Text = "Sorry,login failed!"
            End If
        Else
            LabelErr.Text = "You have failed more than five times."

        End If

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       t = 0

    End Sub
End Class

关于作者

孟繁永 administrator

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据