国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

c#web窗體登錄界面登錄注冊以及密碼找回發送郵箱功能

2024-04-27 15:12:22
字體:
來源:轉載
供稿:網友

c#web窗體登錄界面登錄注冊以及密碼找回發送郵箱功能

效果圖如下:1.登錄界面aspx代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="ebook.Pages.login" %>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../Scripts/jquery-1.8.2.min.js"></script> <title></title> <style type="text/CSS"> .auto-style1 { width: 300px; } .auto-style2 { width: 300px; } .auto-style2 tr td:first-child { //tr里面第一個td text-align: right; width: 100px; } .auto-style2 tr td:last-child { //tr里面最后一個td text-align: left; } </style> <script> $(function () { $("#forgetPwd").click(function () { //登錄界面忘記密碼 $("#LoginSign").css("display", "none"); //登錄界面隱藏 $("#FindPwd").css("display", "block"); //找回密碼界面顯示 }); $("#BtnfindPwd").click(function () { //找回密碼界面的 找回密碼按鈕事件 if ($("#mail").val() == "") { $("#errormsg").text("郵箱不能為空"); } else { $("#errormsg").text(""); //取消后面span標簽的內容顯示 $.post("../Handler/FindPwdHandler.ashx", { "mail": $("#mail").val() }, function success(data) { if (data == "NO") { $("#errormsg").text("郵箱不存在"); //輸入的郵箱不存在 } else { alert("郵箱發送成功!"); } }); } }); }) </script></head><body> <form id="form1" runat="server"> <div id="LoginSign"> <table class="auto-style1"> <tr> <td style="text-align: center"> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="楷體" Font-Size="XX-Large" ForeColor="#3366FF" Text="用戶登錄"></asp:Label> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <table class="auto-style2"> <tr> <td> <asp:Label ID="Label2" runat="server" Text="用戶名:"></asp:Label> </td> <td> <asp:TextBox ID="txt_User_Name" runat="server" TabIndex="1"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label3" runat="server" Text="密碼:"></asp:Label> </td> <td> <asp:TextBox ID="txt_User_Pwd" runat="server" TabIndex="2"></asp:TextBox> <a href="javascript:void(0)" id="forgetPwd">忘記密碼</a> </td> </tr> <tr> <td> <asp:Button ID="btn_Login" runat="server" TabIndex="3" Text="登錄" OnClick="btn_Login_Click" /> </td> <td> <asp:Button ID="btn_Register" runat="server" TabIndex="4" Text="注冊" OnClick="btn_Register_Click" /> </td> </tr> <tr> <td> </td> <td> <asp:Label ID="Labinfo" runat="server" Font-Size="Smaller" ForeColor="Red"></asp:Label> //顯示登錄成功失敗的提示 </td> </tr> </table> </td> </tr> </table> </div> <div id="FindPwd" style="display: none"> <table> <tr> <td> <asp:Label ID="Label5" runat="server" Text="郵箱:"></asp:Label><asp:TextBox ID="mail" runat="server"></asp:TextBox><span id="errormsg"></span></td> </tr> <tr> <td> <input type="button" value="找回密碼" id="BtnfindPwd" /></td> </tr> </table> </div> </form></body></html>
2.登錄界面aspx.cs代碼
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using BLL;using MODEL;using ebook.App_Start;using System.IO;using System.Text;namespace ebook.Pages{    public partial class login : System.Web.UI.Page    {        HuiyuanTablemodel model = new HuiyuanTablemodel();        Logincheckbll bll = new Logincheckbll();        PRotected void Page_Load(object sender, EventArgs e)        {                   }        //登錄        protected void btn_Login_Click(object sender, EventArgs e)        {            model.huiyuanming = this.txt_User_Name.Text.ToString();            model.passWord = this.txt_User_Pwd.Text.ToString();            if(bll.logincheck(model))            {                Labinfo.Text = "登錄成功";               // session["Username"] = this.txt_User_Name.Text.ToString();               // Session[Common.Username] = this.txt_User_Name.Text.ToString();            }            else            {                this.txt_User_Name.Focus();                Labinfo.Text = "登錄失敗";            }                 }        //注冊        protected void btn_Register_Click(object sender, EventArgs e)        {            Response.Redirect("register.aspx");     //頁面跳轉        }    }}3.注冊頁面aspx代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="ebook.Pages.register" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <style type="text/css">        .auto-style1 {            width: 600px;        }        #table2 tr td:first-child {            width: 100px;            text-align: right;        }        #table2 tr td:last-child {            text-align: left;        }        #table2 th {            width: 220px;            text-align: left;        }        .auto-style2 {            height: 23px;        }    </style></head><body>    <form id="form1" runat="server">        <table align="center" class="auto-style1">            <tr>                <td style="text-align: center">                    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="楷體" Font-Size="XX-Large" ForeColor="#3366FF" Text="用戶注冊"></asp:Label>                </td>            </tr>            <tr>                <td> </td>            </tr>            <tr>                <td>                    <table class="auto-style1" id="table2">                        <tr>                            <td>                                <asp:Label ID="Label2" runat="server" Text="用戶名:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_User_Name" runat="server" TabIndex="1"></asp:TextBox>                                *</th>                            <td>                                <asp:Button ID="btn_Check" runat="server" OnClick="btn_Check_Click" TabIndex="2" Text="檢測用戶名" />                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_User_Name" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                            </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label3" runat="server" Text="密碼:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_User_Pwd" runat="server" TabIndex="3"></asp:TextBox>                                *</th>                            <td>                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txt_User_Pwd" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                            </td>                        </tr>                        <tr>                            <td class="auto-style2">                                <asp:Label ID="Label4" runat="server" Text="確認密碼:"></asp:Label>                            </td>                            <th class="auto-style2">                                <asp:TextBox ID="txt_ReUser_Pwd" runat="server" TabIndex="4"></asp:TextBox>                                *</th>                            <td class="auto-style2">                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txt_ReUser_Pwd" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                                <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txt_User_Pwd" ControlToValidate="txt_ReUser_Pwd" ErrorMessage="CompareValidator">兩次輸入的密碼不一致</asp:CompareValidator>                            </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label5" runat="server" Text="姓名:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_Rel_Name" runat="server" TabIndex="5"></asp:TextBox>                                *</th>                            <td>                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txt_Rel_Name" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                            </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label6" runat="server" Text="性別:"></asp:Label>                            </td>                            <th>                                <asp:DropDownList ID="DDL_Sex" runat="server" TabIndex="6">                                    <asp:ListItem>男</asp:ListItem>                                    <asp:ListItem>女</asp:ListItem>                                </asp:DropDownList>                            </th>                            <td> </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label7" runat="server" Text="出生日期:"></asp:Label>                            </td>                            <th>                                <asp:DropDownList ID="DDL_Year" runat="server" TabIndex="7">                                </asp:DropDownList>年                                                             <asp:DropDownList ID="DDL_Month" runat="server" TabIndex="8">                                </asp:DropDownList>月                                                             <asp:DropDownList ID="DDL_Day" runat="server" TabIndex="9">                                </asp:DropDownList>日                            </th>                            <td> </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label8" runat="server" Text="聯系地址:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_Address" runat="server" TabIndex="10"></asp:TextBox>                            </th>                            <td> </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label9" runat="server" Text="郵政編碼:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_Postalcode" runat="server" TabIndex="11"></asp:TextBox>                            </th>                            <td>                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txt_Postalcode" ErrorMessage="RegularExpressionValidator" ValidationExpression="/d{6}">郵政編碼不符合</asp:RegularExpressionValidator>                            </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label10" runat="server" Text="聯系電話:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_Tel" runat="server" TabIndex="12"></asp:TextBox>                                *</th>                            <td>                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txt_Tel" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txt_Tel" ErrorMessage="RegularExpressionValidator" ValidationExpression="^[1][358][0-9]{9}$">聯系電話格式不符合</asp:RegularExpressionValidator>                            </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label11" runat="server" Text="手機:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_Mobile" runat="server" TabIndex="13"></asp:TextBox>                            </th>                            <td> </td>                        </tr>                        <tr>                            <td>                                <asp:Label ID="Label14" runat="server" Text="郵箱:"></asp:Label>                            </td>                            <th>                                <asp:TextBox ID="txt_mail" runat="server" TabIndex="15"></asp:TextBox>                            </th>                            <td class="auto-style2">                                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txt_mail" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                                <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txt_mail" ErrorMessage="RegularExpressionValidator" ValidationExpression="^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(/.[a-zA-Z0-9_-]+)+$">郵箱格式不符</asp:RegularExpressionValidator>                            </td>                        </tr>                        <tr>                            <td class="auto-style2">                                <asp:Label ID="Label12" runat="server" Text="身份證號:"></asp:Label>                            </td>                            <th class="auto-style2">                                <asp:TextBox ID="txt_ID_Card" runat="server" TabIndex="14"></asp:TextBox>                                *</th>                            <td class="auto-style2">                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txt_ID_Card" ErrorMessage="RequiredFieldValidator" ForeColor="Red">此項必填</asp:RequiredFieldValidator>                                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txt_ID_Card" ErrorMessage="RegularExpressionValidator" ValidationExpression="/d{17}[/d|X]|/d{15}">身份證號碼格式不符</asp:RegularExpressionValidator>                            </td>                        </tr>                        <tr>                            <td> </td>                            <th>                                <asp:Button ID="btn_Register" runat="server" OnClick="btn_Register_Click" TabIndex="15" Text="注冊" />                                <asp:Button ID="btn_Catch" runat="server" OnClick="btn_Catch_Click" TabIndex="16" Text="重填" />                                <asp:Label ID="Label13" runat="server" Font-Size="Smaller" ForeColor="Red" Text="帶*的為必填項"></asp:Label>                            </th>                            <td> </td>                        </tr>                    </table>                </td>            </tr>            <tr>                <td style="text-align: center">                    <asp:Label ID="Labinfo" runat="server" Font-Size="Smaller" ForeColor="Red"></asp:Label>                </td>            </tr>        </table>    </form></body></html>4.注冊頁面aspx.cs代碼
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using BLL;using MODEL;using System.Text;using ebook.Common;namespace ebook.Pages{    public partial class register : System.Web.UI.Page    {        Registerbll bll = new Registerbll();        HuiyuanTablemodel model = new HuiyuanTablemodel();        static string statu;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)                              //頁面初次加載            {                #region 初始化年、月、日                for (int year = 1930; year <= 2008; year++)                {                    DDL_Year.Items.Add(year.ToString());                }                for (int month = 1; month <= 12; month++)                {                    DDL_Month.Items.Add(month.ToString());                }                for (int day = 1; day <= 31; day++)                {                    DDL_Day.Items.Add(day.ToString());                }                #endregion                //按鈕不觸發驗證事件                this.btn_Catch.CausesValidation = false;   //注冊事件                this.btn_Check.CausesValidation = false;   //檢測用戶名事件            }        }        //注冊        protected void btn_Register_Click(object sender, EventArgs e)        {            #region 獲取輸入表的信息            model.huiyuanming = this.txt_User_Name.Text.ToString();            //md5加密            MD5 a = new MD5();  //錯誤方法            string md5Pwd = a.jiamiMD5(this.txt_User_Pwd.Text.ToString());            model.password = md5Pwd;            model.name = this.txt_Rel_Name.Text.ToString();            model.sex = DDL_Sex.SelectedIndex.ToString();//0代表男   1代表女            StringBuilder brithday1 = new StringBuilder();            brithday1.Append(DDL_Year.SelectedItem);            brithday1.Append("-");            brithday1.Append(DDL_Month.SelectedItem);            brithday1.Append("-");            brithday1.Append(DDL_Day.SelectedItem);            model.brithday = Convert.ToDateTime(brithday1.ToString());            model.address = this.txt_Address.Text.ToString();            model.postal = this.txt_Postalcode.Text.ToString();            model.phone = this.txt_Tel.Text.ToString();            model.telphone = this.txt_Mobile.Text.ToString();            model.idcard = this.txt_ID_Card.Text.ToString();            model.mail = this.txt_mail.Text.ToString();            #endregion            //statu有null,true,false三個狀態,null代表沒有檢測用戶名,直接注冊提交,true代表檢測用戶名成功,注冊。 false代表檢測用戶名失敗,            if (statu == null)            {                string name = txt_User_Name.Text;                if (bll.Search(name))                {                    Labinfo.Text = "對不起,此用戶已經被注冊,請輸入其他用戶名!";                }                else                {                    if (bll.insert(model))                    {                        Response.Write("<script>alert('注冊成功!')</script>");                    }                    else                    {                        Response.Write("<script>alert('注冊失?。?)</script>");                    }                }            }            else if (statu == "true")            {                if (bll.insert(model))                {                    Response.Write("<script>alert('注冊成功!')</script>");                    statu = null;                }                else                {                    Response.Write("<script>alert('注冊失??!')</script>");                }            }            else            {                Response.Write("<script>alert('用戶名相同!')</script>");            }        }        //重填        protected void btn_Catch_Click(object sender, EventArgs e)        {            this.txt_User_Name.Focus();            this.txt_User_Name.Text = "";            this.txt_User_Pwd.Text = "";            this.txt_ReUser_Pwd.Text = "";            this.txt_Rel_Name.Text = "";            this.txt_Address.Text = "";            this.txt_Postalcode.Text = "";            this.txt_ID_Card.Text = "";            this.txt_Mobile.Text = "";            this.txt_Tel.Text = "";            this.DDL_Sex.SelectedIndex = 0;            this.DDL_Year.SelectedIndex = 0;            this.DDL_Month.SelectedIndex = 0;            this.DDL_Day.SelectedIndex = 0;        }        //檢測用戶名        protected void btn_Check_Click(object sender, EventArgs e)        {            string name = txt_User_Name.Text;            if (bll.Search(name))            {                Labinfo.Text = "對不起,此用戶已經被注冊,請輸入其他用戶名!";                statu = "false";            }            else            {                Labinfo.Text = "恭喜您,此用戶名可以使用!";                statu = "true";            }        }    }}4.找回密碼,發送到郵箱
  <div id="FindPwd" style="display: none">            <table>                <tr>                    <td>                        <asp:Label ID="Label5" runat="server" Text="郵箱:"></asp:Label><asp:TextBox ID="mail" runat="server"></asp:TextBox><span id="errormsg"></span></td>                </tr>                <tr>                    <td>                        <input type="button" value="找回密碼" id="BtnfindPwd" /></td>                </tr>            </table>        </div>
 <script>        $(function () {            $("#forgetPwd").click(function () {                $("#LoginSign").css("display", "none");                $("#FindPwd").css("display", "block");            });            $("#BtnfindPwd").click(function () {                if ($("#mail").val() == "") {                    $("#errormsg").text("郵箱不能為空");                }                else {                    $("#errormsg").text("");                    $.post("../Handler/FindPwdHandler.ashx", { "mail": $("#mail").val() }, function success(data) {                        if (data == "NO") {                            $("#errormsg").text("郵箱不存在");                        }                        else {                            alert("郵箱發送成功!");                        }                    });                }            });        })    </script>5 .../Handler/FindPwdHandler.ashx代碼
using System;using System.Collections.Generic;using System.Linq;using System.Web;using BLL;using System.Net.Mail;  //郵箱發送的引用文件using System.Net;       //身份驗證的引用文件using System.Text;using ebook.Common;namespace ebook.Handler{    /// <summary>    /// FindPwdHandler 的摘要說明    /// </summary>    public class FindPwdHandler : IHttpHandler    {        Checkmail checkmail = new Checkmail();        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            string mail = context.Request["mail"];            if (checkmail.CheckmailISnull(mail))            //mail存在,發送郵件            {                sendMail(mail);            }            else            {                context.Response.Write("NO");            }        }        private void sendMail(string mail)        {            string newPwd = Guid.NewGuid().ToString().Substring(0, 6);           //隨機創建一個新的密碼            string userid = checkmail.GetuseridBymail(mail);                     //通過郵箱找到賬戶名稱            MD5 md5 = new MD5();            if (updatePwd(userid, md5.jiamiMD5(newPwd)))                         //密碼更新成功在發送郵件            {                try                {                    MailMessage mailMsg = new MailMessage();                                 //MailMessage引用using System.Net.Mail;                    mailMsg.From = new MailAddress("xxxxx@163.com", "小紅");                 //源郵件地址                    mailMsg.To.Add(new MailAddress("xxxxx@163.com", "asd"));                 //接收人地址                    mailMsg.SubjectEncoding = Encoding.GetEncoding(936);                     //這里非常重要,如果你的郵件標題包含中文,這里一定要指定,否則對方收到的極有可能是亂碼。                    mailMsg.Subject = "找回密碼";                                            //標題                    mailMsg.BodyEncoding = Encoding.GetEncoding(936);                        //郵件正文的編碼, 設置不正確, 接收者會收到亂碼                    StringBuilder sb = new StringBuilder();                    sb.Append("您在xxx網修改密碼");                    sb.Append("您的ID:" + userid);                    sb.Append("密碼:" + newPwd);                    mailMsg.Body = sb.ToString();                                            //郵件正文                    mailMsg.IsBodyHtml = true;                                               //郵件正文是否是HTML格式                    //指定Smtp服務地址                    SmtpClient Client = new SmtpClient("smtp.163.com");                      //smtp.136.com smtp.QQ.com                    Client.Credentials = new NetworkCredential("xxxxxx@163.com", "xxxxx");   //NetworkCredential引用using System.Net; 發件人的郵箱和密碼                    Client.Send(mailMsg);                }                catch (Exception ex)                {                    throw ex;                }            }            else            {                //不發送郵箱,因為密碼更新失?。。?           }        }         private bool updatePwd(string userid, string Pwd)               //更新舊密碼        {            if (checkmail.updatePwd(userid, Pwd))            {                return true;            }            else            {                return false;            }        }        public bool IsReusable        {            get            {                return false;            }        }    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 喀喇| 东源县| 邵武市| 招远市| 固始县| 西吉县| 福海县| 凤山市| 腾冲县| 磐石市| 清新县| 大渡口区| 化州市| 布尔津县| 浦东新区| 安丘市| 衡水市| 商河县| 咸丰县| 汉川市| 苏州市| 达尔| 仁寿县| 弋阳县| 彩票| 炉霍县| 三明市| 中卫市| 任丘市| 金坛市| 德令哈市| 湖口县| 礼泉县| 兴和县| 光山县| 郓城县| 文水县| 贺州市| 黎城县| 固镇县| 谢通门县|