【ADO.NET基礎-Regidter】簡單的賬戶註冊介面和原始碼(可用於簡單面試基礎學慣用)

來源:互聯網
上載者:User

標籤:nic   return   load   bytes   static   .net   body   建議   cat   

在閱讀時如有問題或者建議,歡迎指出和提問,我也是初學者.........

前台代碼:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">  <title></title> </head> <body>  <div align="center">  <h1>使用者登入頁面</h1>  <form id="form1" runat="server">   <p> <asp:Label ID="lbusername" runat="server">學號:</asp:Label>    <asp:TextBox ID="txtNum" runat="server"></asp:TextBox>    </p>      <p> <asp:Label ID="lblName" runat="server">姓名:</asp:Label>    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>    </p>     <p> <asp:Label ID="lbpsw" runat="server">密 碼:</asp:Label>   <asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>   </p>        <p>         <asp:Label ID="lblText" runat="server" Text=""></asp:Label></p>  <p> <asp:Button ID="btnRegister" runat="server" Text="註冊" onclick="btnRegister_Click" />   </p>      </form>  </div> </body> </html>

後台代碼:

using System;using System.Data.SqlClient;using System.Data;using System.Configuration;using System.Drawing;using System.Text;using System.Security.Cryptography;namespace ado.netDemo1{    public partial class register : System.Web.UI.Page    {        SqlConnection connStr = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ToString());        string sql;        protected void Page_Load(object sender, EventArgs e)        {        }        protected void btnRegister_Click(object sender, EventArgs e)        {            if (txtNum.Text.Trim() == "" || txtName.Text.Trim() == "" || txtpwd.Text.Trim() == "")            {                lblText.ForeColor = Color.Red;                lblText.Text = "請將個人資訊填寫完整!";            }            else if (txtNum.Text.Trim() == "" && txtName.Text.Trim() == "" && txtpwd.Text.Trim() == "")            {                lblText.ForeColor = Color.Red;                lblText.Text = "請將個人資訊填寫完整!";            }            else            {                   //加密處理註冊Password                string hashedpwd=Encrypt(txtpwd.Text.Trim());                sql = "insert into tb_Students(SID,Name,Password)Values(‘" + txtNum.Text.Trim() + "‘,‘" + txtName.Text.Trim() + "‘,‘" + hashedpwd + "‘)";                connStr.Open();                SqlCommand cmd = new SqlCommand(sql, connStr);                int i = cmd.ExecuteNonQuery();                if (i == 1)                {                    lblText.ForeColor = Color.Red;                    lblText.Text = "註冊成功!";                    Response.Write(@"<script>window.alert(‘請到登陸介面登陸!‘);window.location=‘Login.aspx‘</script>");                }            }        }        public static string Encrypt(string cleanString)        {            Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);            Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);                    return BitConverter.ToString(hashedBytes);                    }    }}

 

介面:

 

 

【ADO.NET基礎-Regidter】簡單的賬戶註冊介面和原始碼(可用於簡單面試基礎學慣用)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.