Asp.net login foreground background source code

Source: Internet
Author: User

Front-end code:

<Head>
<Title> </title>
<Style type = "text/css">
Body {font: 12px Helvetica, Arial, sans-serif; margin: 100px auto; padding: 0; word-wrap: break-word; word-break: break-all; background-color: #016BA9 ;}
. Login1 {background-image: url (../Images/login_1.jpg); width: 960px; height: 94px; margin: 0 auto ;}
. Login2 {background-image: url (../Images/login_2.jpg); width: 960px; height: 49px; margin: 0 auto ;}
. Login3 {background-image: url (../Images/login_3.jpg); width: 960px; height: 125px; margin: 0 auto ;}
. Login4 {background-image: url (../Images/login_4.jpg); width: 960px; height: 91px; margin: 0 auto ;}
. LoginTXT {border: 1px solid #800000; width: 150px; background-color: #866961; color: # fff; height: 19px ;}
</Style>
<Script type = "text/javascript">
If (top. location! = Self. location)
Top. location = self. location;

Function CheckIn (){
Var names = document. getElementById ("txtU_Name"). value;
Var pass = document. getElementById ("txtU_Pass"). value;
Var check = document. getElementById ("txtU_Check"). value;
If (names = ""){
Alert ("Enter the user name ...");
Document. getElementById ("txtU_Name"). focus ();
Return false;
}
Else if (pass = ""){
Alert ("enter your password ...");
Document. getElementById ("txtU_Pass"). focus ();
Return false;
}
Else if (check = ""){
Alert ("Enter the verification code ...");
Document. getElementById ("txtU_Check"). focus ();
Return false;
}
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server" defaultfocus = "txtU_Name" defaultbutton = "BtnLogin">
<Div class = "login1"> </div>
<Div class = "login2"> </div>
<Div class = "login3">
<Table cellpadding = "0" cellspacing = "1" border = "0" style = "margin-left: 320px; width: 300px;">
<Tr>
<Td> User name: </td>
<Td> <asp: textbox ID = "txtU_Name" runat = "server" class = "loginTXT" maxlength = "20"> </asp: textbox> </td>
</Tr>
<Tr>
<Td> User Password: </td>
<Td> <input id = "txtU_Pass" type = "password" runat = "server" class = "loginTXT" maxlength = "6"/> </td>
</Tr>
<Tr>
<Td> Verification Code: </td>
<Td> <asp: textbox ID = "txtU_Check" runat = "server" class = "loginTXT" style = "width: 85px;" maxlength = "5"/> & nbsp; </td>
</Tr>
<Tr>
<Td colspan = "2"> </Tr>
<Tr>
<Td> </td>
<Td>
<Asp: button ID = "BtnLogin" runat = "server" text = "Logon management" OnClientClick = "return CheckIn ()" onclick = "BtnLogin_Click"/>
& Nbsp; <asp: button ID = "BtnHome" runat = "server" text = "back to homepage"
Onclick = "BtnHome_Click"/>
</Td>
</Tr>
</Table>
</Div>
<Div class = "login4"> </div>
</Form>
</Body>
</Html>

 

 

 

 

 

Background code:

 

 

Protected void BtnLogin_Click (object sender, EventArgs e)
{
String username = txtU_Name.Text;
String pwd = txtU_Pass.Value;
String check = txtU_Check.Text;

If (CheckNull ())
{
If (check. ToString (). ToLower () = Session ["ValidateCode"]. ToString (). ToLower ())
{
String strsql = "select count (1) from Login where UserName = '" + username + "' and UserPwd = '" + pwd + "'";
Object obj = SqlHelper. ExecuteScalar (ConfigurationManager. ConnectionStrings ["conn"]. ToString (), CommandType. Text, strsql );
If (obj! = Null & (int) obj> 0)
{
Response. Write ("<script> alert ('logon successful! ') </Script> ");
Session ["username"] = username;

HttpCookie hc = new HttpCookie ("username", username );
Hc. Expires = DateTime. Now. AddMinutes (1 );
Response. Cookies. Add (hc );

Response. Redirect ("Main. aspx ");
}
Else
{
Response. Write ("<script> alert ('user name or password is incorrect! ') </Script> ");
Response. Write ("<script> window. location. href = 'login. aspx '</script> ");
}
}
Else
{
Response. Write ("<script> alert ('verification code error! ') </Script> ");
Response. Write ("<script> window. location. href = 'login. aspx '</script> ");

}
}


}
Private bool CheckNull ()
{
Return (! (String. IsNullOrEmpty (txtU_Name.Text.Trim ()))&&! (String. IsNullOrEmpty (txtU_Pass.Value.Trim ()))&&! (String. IsNullOrEmpty (txtU_Check.Text.Trim ())))? True: false;
}

 

Main homepage code: page_Load

Try
{
String username = Session ["username"]. ToString ();
}
Catch
{
Response. Write ("<script> alert ('Log On from the homepage! '); Location. href = 'login. aspx'; </script> ");
}

 

 

This article from the "cainiao" blog, please be sure to keep this source http://wolfoo.blog.51cto.com/3126463/1288217

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.