A login registration interface written by connecting to the database with ASP. NET

Source: Internet
Author: User

Welcome. aspx Design
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "Welcome. aspx. cs" inherits = "_ 10_17. database creation. Welcome" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
Congratulations! login successful!
</Div>
</Form>
</Body>
</Html>

Design of welcome. aspx. CS
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Namespace _ 10_17. database creation
{
Public partial class welcome: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{

}
}
Protected void page_unload (Object sender, eventargs E)
{

}

}

 

Yanzheng. aspx Design
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "yanzheng. aspx. cs" inherits = "_ 10_17. database creation. yanzheng" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

</Div>
</Form>
</Body>
</Html>

Yanzheng. aspx. CS Design
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Namespace _ 10_17. database creation
{
Public partial class yanzheng: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Response. contenttype = "image/JPEG ";
Using (system. Drawing. Bitmap bitmap = new system. Drawing. Bitmap (57, 27 ))
{
Using (system. Drawing. Graphics G = system. Drawing. Graphics. fromimage (Bitmap ))
{
Random Rand = new random ();
Int code = Rand. Next (1000,999 9 );
String vercode = code. tostring ();
Session ["code"] = vercode;

G. drawstring (vercode, new system. Drawing. Font ("", 19), system. Drawing. Brushes. Green, 0, 0 );
Bitmap. Save (response. outputstream, system. Drawing. imaging. imageformat. JPEG );

}
}
}
}
}

Successful. aspx Design
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "successful. aspx. cs" inherits = "_ 10_17. database creation. Successful" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<SCRIPT type = "text/JavaScript">
SetTimeout (function (){
Location. href = '<% = request ["redirecturl"] %> ';

},3000 );
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "LBL" runat = "server" text = "label"> </ASP: Label>
</Div>
</Form>
</Body>
</Html>

Successful. aspx. CS Design
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Namespace _ 10_17. database creation
{
Public partial class successful: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
LBL. Text = request ["MSG"];
}
}
}

Login interface. aspx Design
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "Logon interface. aspx. cs" inherits = "_ 10_17. database creation. logon interface" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>

<Table align = "center"> <tr> <TD> </TD> <TD>
<Asp: Label id = "label1" runat = "server" text = "Logon interface"> </ASP: Label> </TD> </tr> </table>
<Table align = "center">

<Tr> <TD> User name: </TD> <TD>
<Asp: textbox id = "txtusername" runat = "server"> </ASP: textbox> </TD> <TD>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator2" runat = "server"

Errormessage = "cannot be blank" forecolor = "red" controltovalidate = "txtusername"> </ASP: requiredfieldvalidator> </TD> </tr>
<Tr> <TD> password: </TD> <TD>
<Asp: textbox id = "txtpassword" runat = "server"> </ASP: textbox> </TD> <TD>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator1" runat = "server"

Errormessage = "cannot be blank" controltovalidate = "txtpassword" forecolor = "red"> </ASP: requiredfieldvalidator> </TD>
</Tr>

<Tr> <TD> </TD>
<TD> <asp: textbox id = "textbox1" runat = "server"> </ASP: textbox> </TD>
</Tr>



<Tr> <TD align = "center" colspan = "2">
<Asp: button id = "btnlogin" runat = "server" text = "login" onclick = "btnlogin_click"

Height = "21px" width = "45px"/>
<Asp: button id = "btnregister"
Runat = "server" text = "register" Height = "21px" width = "45px"
Causesvalidation = "false" onclick = "btnregister_click"/> </TD> </tr>

</Table> <asp: Label id = "lblerrormessage" runat = "server" visible = "false"> </ASP: Label>
</Div>
</Form>
</Body>
</Html>

 

Design of 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 _ 10_17. database;

Namespace _ 10_17. database creation
{
Public partial class logon interface: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

Protected void btnlogin_click (Object sender, eventargs E)
{
String username = txtusername. text;
String Password = txtpassword. text;

String coonstr = "Data Source = PC-20120416OTQL; initial catalog = userdb1; persist Security info = true; user id = sa; Password = admin ";

Using (sqlconnection coon = new sqlconnection (coonstr ))
{
Coon. open ();
Using (sqlcommand cmd = coon. createcommand ())
{
Cmd. commandtext = "select * From t_username where
Username = @ name ";
Cmd. Parameters. Add (New sqlparameter ("@ name", username ));

Sqldatareader reader = cmd. executereader ();
If (reader. Read () = true & textbox1.text = session ["code"]. tostring ())
{
String Pwd = reader. getstring (reader. getordinal ("password "));
If (Pwd = PASSWORD)
{
// The user name exists.
This. lblerrormessage. Visible = false;
Response. Redirect ("~ /Database creation/welcome. aspx ");
}
Else
{
This. lblerrormessage. Visible = true;
This. lblerrormessage. Text = "Incorrect password ";


}
}
Else
{
This. lblerrormessage. Visible = true;
This. lblerrormessage. Text = "incorrect user name or verification code ";

}
}
}
# Region
Object result = sqlhelper. executescalar ("select * From t_username where
Username = @ name ", new sqlparameter (" @ name ", username ));
If (convert. toint64 (result)> 0)
{
Response. Redirect ("Welcome. aspx ");
}
Else
{

}
# Endregion
}

Protected void btnregister_click (Object sender, eventargs E)
{

Response. Redirect ("~ /Database creation/registration interface. aspx ");

}


}
}

 

Registration interface. aspx Design
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "registration interface. aspx. cs" inherits = "_ 10_17. database creation. Registration interface" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Table align = "center"> <tr> <TD> </TD> <TD>
<Asp: Label id = "label1" runat = "server" text = "registration interface"> </ASP: Label> </TD> </tr> </table>
<Table align = "center">
<Tr> <TD> User name: </TD> <TD>
<Asp: textbox id = "txtusername" runat = "server"> </ASP: textbox> </TD> <TD>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator1" runat = "server"

Errormessage = "cannot be blank" controltovalidate = "txtusername"
Forecolor = "red"> </ASP: requiredfieldvalidator> </TD>
</Tr>
<Tr> <TD> password: </TD> <TD>
<Asp: textbox id = "txtpassword" runat = "server"> </ASP: textbox> </TD>
<TD>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator2" runat = "server"

Errormessage = "cannot be blank" controltovalidate = "txtpassword"
Forecolor = "red"> </ASP: requiredfieldvalidator> </TD>

</Tr>
<Tr> <TD> Email: </TD> <TD>
<Asp: textbox id = "txtemail" runat = "server"> </ASP: textbox> </TD>
<TD>
<Asp: requiredfieldvalidator id = "requiredfieldvalidator3" runat = "server"

Errormessage = "cannot be blank" controltovalidate = "txtemail" forecolor = "red"> </ASP: requiredfieldvalidator> </TD> </tr>
<Tr> <TD colspan = "2" align = "center">
<Asp: button id = "btnregister" runat = "server" text = "register"
Onclick = "btnregister_click" style = "height: 21px"/> </TD> </tr>
</Table>
</Div>
</Form>
</Body>
</Html>

 

Design of Aspx. CS on the registration page
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 _ 10_17. database;

Namespace _ 10_17. database creation
{
Public partial class registration interface: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

Protected void btnregister_click (Object sender, eventargs E)
{
String username = txtusername. text;
String Password = txtpassword. text;
String email = txtemail. text;

String coonstr = "Data Source = PC-20120416OTQL; initial catalog = userdb1; persist Security info = true; user id = sa; Password = admin ";

Using (sqlconnection coon = new sqlconnection (coonstr ))
{

Coon. open ();
Using (sqlcommand cmd = coon. createcommand ())
{
Cmd. commandtext = "insert into t_username (username, password, email) values (@ name, @ PWD, @ em )";
Cmd. Parameters. Add (New sqlparameter ("@ name", username ));

Cmd. Parameters. Add (New sqlparameter ("@ PWD", password ));

Cmd. Parameters. Add (New sqlparameter ("@ em", email ));
Cmd. executenonquery ();

Response. Redirect ("~ /Database creation/successful. aspx? MSG = registration successful, will jump to the login interface & redirecturl = login interface. aspx ");

}
}

}
}
}

 

Related Article

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.