Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim username As String = Me.Login1.UserName
Dim userpass As String = Me.Login1.Password
Dim b As String = Me.Login1.RememberMeSet
Dim conn As MySql.Data.MySqlClient.MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection("Server=127.0.0.1;Database=mydata;User Id=root;Password=;Character Set=gbk")
Dim comm As MySql.Data.MySqlClient.MySqlCommand = New MySql.Data.MySqlClient.MySqlCommand("select count(*) from t_user where username = ?username and userpass = ?userpass", conn)
comm.Parameters.AddWithValue("username", username)
comm.Parameters.AddWithValue("userpass", userpass)
conn.Open()
Dim o As Object = comm.ExecuteScalar()
Dim i As Integer = Convert.ToInt32(o)
conn.Close()
If i < 1 Then
Return
End If
Response.Cookies("username").Value = username
Response.Cookies("userpass").Value = userpass
If b Then
Response.Cookies("username").Expires = DateTime.Now.AddDays(1)
Response.Cookies("userpass").Expires = DateTime.Now.AddDays(1)
End If
Response.Redirect("~/Index.aspx")
End Sub
End Class