当前位置:网站首页>asp. Net registration page
asp. Net registration page
2022-06-28 07:41:00 【No. 1006 Xiaobai】
Registration page , The effect is as follows 
RequiredFieldValidator Control : Verify the input , This article verifies the input box
One of the more common attributes :
ErrorMessage="* mandatory " : Prompt for verification failure
ForeColor: The font color of the error message .
ControlToValidate: Of the validated control id
runat=“server” This control is a server control
<body style="background:#d7eeee;">
<form id="form1" runat="server" >
<div class="container" >
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6 login_text2">X Animation model website registration </div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3 login_text"> user name :</div>
<div class="col-md-6" >
<asp:TextBox ID="txtUser" class="form-control" runat="server"></asp:TextBox>
</div>
<div class="col-md-3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* mandatory " ControlToValidate="txtUser"></asp:RequiredFieldValidator>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 login_text"> Set the password :</div>
<div class="col-md-6 ">
<asp:TextBox ID="txtPwd" runat="server" class="form-control" TextMode="Password"></asp:TextBox>
</div>
<div class="col-md-3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* mandatory " ControlToValidate="txtPwd"></asp:RequiredFieldValidator>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 login_text"> Confirm the password :</div>
<div class="col-md-6 ">
<asp:TextBox ID="txtPwd2" runat="server" class="form-control" TextMode="Password"></asp:TextBox>
</div>
<div class="col-md-3">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="* mandatory " ControlToValidate="txtPwd"></asp:RequiredFieldValidator>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 login_text"> Verification Code :</div>
<div class="col-md-6">
<asp:TextBox ID="txtCheckCode" class="form-control" Width="150" runat="server"></asp:TextBox>
</div>
<div class="col-md-3" style="margin-top:5px">
<asp:Image ID="Image1" runat="server" ImageUrl="~/CheckCode.aspx" /></div>
</div>
</div>
<div class="form-group header_signup">
<asp:Button ID="btnlogon2" CssClass="header_login2" runat="server" Text=" register " OnClick="btnlogon2_Click" />
<asp:Button ID="ImageButton2" CssClass="header_login2" runat="server" Text=" Reset " OnClick="btnlogon3_Click"/>
<asp:HyperLink ID="HyperLink1" runat="server" class="btn-link" NavigateUrl="~/Default.aspx">[ Back to the home page ]</asp:HyperLink>
</div>
</div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6"></div>
<div class="col-md-3"></div>
</div>
</div>
</form>
</body>
At the bottom is btnlogon3_Click It is to realize the empty function , When the user clicks empty, the input box will be cleared
First, judge whether the password entered twice is correct 、 Then judge whether the verification code is correct
checkcode = Request.Cookies[“CheckCode”].Value; Get the value of the verification code
The implementation of the verification code is shown below
WebMessageBox.Show(“ congratulations , Registered successfully , Please login page !”, “Logon.aspx”); Output the prompt box and jump to the page , You can pass Response.Write Realization
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login : System.Web.UI.Page
{
// Declare user classes and random variables
Operation operation = new Operation();
Random random = new Random();
String checkcode = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnlogon2_Click(object sender, EventArgs e)
{
// utilize CheckCode Realize picture display
checkcode = Request.Cookies["CheckCode"].Value;
// Determine whether the passwords you re-enter are consistent
if (txtPwd.Text == txtPwd2.Text)
{
// Determine whether the verification code is correct
if (checkcode != txtCheckCode.Text.Trim())
{
WebMessageBox.Show(" The input verification code is incorrect !", "Login.aspx");
}
else if (true)
{
// Add data to the database
operation.Login(txtUser.Text, txtPwd2.Text);
// Judge whether the data is successfully added to the database
if (operation.Login2(txtUser.Text, txtPwd2.Text).Tables[0].Rows.Count > 0) {
WebMessageBox.Show(" congratulations , Registered successfully , Please login page !", "Logon.aspx");
}
else
{
WebMessageBox.Show(" Registration failed , Please re register !", "Login.aspx");
}
}
}
else {
WebMessageBox.Show(" The confirmation password entered is not equal to the password , Please re-enter !", "Login.aspx");
}
}
protected void btnlogon3_Click(object sender, EventArgs e)
{
txtUser.Text = "";
txtPwd.Text = "";
txtPwd2.Text = "";
txtCheckCode.Text = "";
}
}
Implementation of verification code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class CheckCode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreateCheckCodeImage(GenerateCheckCode());
}
private string GenerateCheckCode()
{
int number;
char code;
string checkCode = String.Empty;
System.Random random = new Random();
for (int i = 0; i < 4; i++)
{
number = random.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkCode += code.ToString();
}
Response.Cookies.Add(new HttpCookie("CheckCode", checkCode));
return checkCode;
}
private void CreateCheckCodeImage(string checkCode)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
Graphics g = Graphics.FromImage(image);
try
{
// Generate random generator
Random random = new Random();
// Clear the background color of the picture
g.Clear(Color.White);
// Draw the background noise line of the picture
for (int i = 0; i < 2; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Black), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 2);
// Draw the foreground noise point of the picture
for (int i = 0; i < 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
// Draw the border line of the picture
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
}
边栏推荐
猜你喜欢

es6箭头函数中return的用法

Resizing node of rediscluster cluster cluster mode

推荐系统系列精讲(第五讲): 排序模型的调优实践

Porting ucosiii to stm32f429

HTTP Caching Protocol practice

Introduction and several months' experience of extending the solution thanos of Prometheus

Recommended system series (Lecture 5): Optimization Practice of sorting model

Static resource compression reduces bandwidth pressure and increases access speed

Modifying MySQL port number under Linux

阿里云服务器创建快照、回滚磁盘
随机推荐
Section 8: DMA of zynq
Investment transaction and settlement of the fund
HJ删除字符串中出现次数最少的字符
Mysql8.0 and mysql5.0 accessing JDBC connections
Is it safe for flush to open an account online
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
A single node obtains the lock lock of the order number
vite2.9 中指定路径别名
Evaluation of inverse Polish expression < difficulty coefficient >
Hash slot of rediscluster cluster cluster implementation principle
Conversion between HJ integer and IP address
大型项目中的Commit Message规范化控制实现
How to configure DDR3 of dm8148
Update pip to the latest version
Mysql8.0和Mysql5.0访问jdbc连接
HJ明明的随机数
mysql57 zip文件安装
The practice of event driven architecture in vivo content platform
R 语言绘制 动画气泡图
Is it reliable to open a new bond registration account? Is it safe?
