ASP.NEP 網頁的記住密碼
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
public partial class da : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
} protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text.Trim()!=null && TextBox2.Text.Trim()!=null) { Session["username"] = TextBox1.Text.Trim(); if (CheckBox1.Checked) { if (Request.Cookies["username"] == null) { Response.Cookies["username"].Expires = DateTime.Now.AddDays(30); Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(30); Response.Cookies["username"].Value = TextBox1.Text.Trim(); Response.Cookies["userpwd"].Value = TextBox2.Text.Trim(); } } Response.Redirect("db.aspx"); } else { ClientScript.RegisterStartupScript(this.GetType(), "", "alert('使用者名稱或密碼錯誤!');", true); } } protected void TextBox1_TextChanged(object sender, EventArgs e) { if(Request.Cookies["username"]!=null) { if(Request.Cookies["username"].Value.Equals(TextBox1.Text.Trim())) { TextBox2.Text = Request.Cookies["userpwd"].Value; } } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = null; TextBox2.Text = null; Response.Cookies.Clear(); } }