One verification code creation: generates a four-digit random number.

Source: Internet
Author: User
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;

Public partial class usecontrols_header: system. Web. UI. usercontrol
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
// Generate a random number (4 digits) and display it as a verification code during initialization.
Random YZM = new random ();
This. labvali. Text = YZM. Next (1000,999 9). tostring ();
}
}

Protected void btnreg_click (Object sender, eventargs E)
{
Page. response. Redirect ("~ /Module/blog/regpro. aspx ");
}

Protected void btnok_click (Object sender, eventargs E)
{
If (this.txt vali. Text! = This. labvali. Text)
{
Response. Write ("<SCRIPT Lanuage = JavaScript> alert ('verification code error'); location = 'javascript: history. Go (-1) '</SCRIPT> ");
}
Else
{
Sqlconnection con = new sqlconnection (configurationmanager. etettings ["constr"]);
Con. open ();
Sqlcommand COM = new sqlcommand ("select count (*) from tb_blog where username = '" + this.txt uid. text + "'and Password ='" + this.txt PWD. text + "'", con );
Int COUNT = convert. toint32 (COM. executescalar ());
If (count> 0)
{
Session ["username"] = this.txt uid. text;
Session ["password"] = this.txt PWD. text;
Page. response. Redirect ("module/blog/index. aspx ");
}
Else
{
Response. Write ("<SCRIPT Lanuage = JavaScript> alert ('user name or password is incorrect! '); Location = 'javascript: history. Go (-1)' </SCRIPT> ");
Return;
}
}
}
}

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.