我有一个登录表单,我想制作一个带有记住我功能的复选框......谁能给我一些如何制作它的代码?我没有尝试任何东西,因为我不知道..
int timeout = rememberMe ? 525600 : 30; // Timeout in minutes, 525600 = 365 days.
var ticket = new FormsAuthenticationTicket(userName, rememberMe, timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = System.DateTime.Now.AddMinutes(timeout);// Not my line
cookie.HttpOnly = true; // cookie not available in javascript.
Response.Cookies.Add(cookie);
我找到了这个,但我不知道放在哪里..
其余的代码是:
using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM members WHERE username = '" + textBox2.Text + "' AND password = '" + textBox3.Text + "';"))
{
cmd.Connection = con;
DataTable dt = new DataTable();
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() != false)
{
if (reader.IsDBNull(0) == true)
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
MessageBox.Show("Oops!There was a problem!");
}
else
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
this.Hide();
}
}
else
{
MessageBox.Show("You Login Information is incorrect!");
}