"ADO. NET Foundation-regidter "Simple account Registration interface and source code (can be used for simple interview basic Learning)

Source: Internet
Author: User

If you have questions or suggestions when reading, please point out and ask questions, I am also a beginner ...

Front Code:

<! DOCTYPE html>"http://www.w3.org/1999/xhtml"> "Server"> <title></title> "Center"> "Form1"runat="Server"> <p> <asp:label id="Lbusername"runat="Server"> No.:</asp:label> <asp:textbox id="Txtnum"runat="Server"></asp:TextBox> </p> <p> <asp:label id="Lblname"runat="Server"> Name:</asp:label> <asp:textbox id="txtname"runat="Server"></asp:TextBox> </p> <p> <asp:label id="LBPSW"runat="Server"> Password:</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="Register"onclick="Btnregister_click"/> </p> </form> </div> </body> 

Background code:

usingSystem;usingSystem.Data.SqlClient;usingSystem.Data;usingSystem.Configuration;usingSystem.Drawing;usingSystem.Text;usingSystem.Security.Cryptography;namespaceado.netdemo1{ Public Partial classregister:System.Web.UI.Page {SqlConnection connstr=NewSqlConnection (configurationmanager.connectionstrings["ConnStr"].        ToString ()); stringSQL; protected voidPage_Load (Objectsender, EventArgs e) {        }        protected voidBtnregister_click (Objectsender, EventArgs e) {            if(TxtNum.Text.Trim () = =""|| TxtName.Text.Trim () = =""|| Txtpwd. Text.trim () = ="") {Lbltext.forecolor=color.red; Lbltext.text="please complete the personal information! "; }            Else if(TxtNum.Text.Trim () = =""&& TxtName.Text.Trim () = =""&& txtpwd. Text.trim () = ="") {Lbltext.forecolor=color.red; Lbltext.text="please complete the personal information! "; }            Else            {                   //Cryptographic processing Registration Password                stringHashedpwd=Encrypt (txtpwd.                Text.trim ()); SQL="INSERT INTO tb_students (Sid,name,password) Values ('"+ TxtNum.Text.Trim () +"', '"+ TxtName.Text.Trim () +"', '"+ Hashedpwd +"')";                Connstr.open (); SqlCommand cmd=NewSqlCommand (SQL, CONNSTR); inti =cmd.                ExecuteNonQuery (); if(i = =1) {Lbltext.forecolor=color.red; Lbltext.text="Registration Successful! "; Response.Write (@"<script>window.alert (' Please login to login screen! '); window.location= ' Login.aspx ' </script>"); }            }        }         Public Static stringEncrypt (stringcleanstring) {byte[] clearbytes=Newunicodeencoding ().            GetBytes (cleanstring); Byte[] Hashedbytes= ((HashAlgorithm) Cryptoconfig.createfromname ("MD5")).                    ComputeHash (clearbytes); returnbitconverter.tostring (hashedbytes); }    }}

Interface:

"ADO. NET Foundation-regidter "Simple account Registration interface and source code (can be used for simple interview basic Learning)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.