zoukankan
html css js c++ java
ASP.net 验证码(C#)
public
class
ValidateCode : System.Web.UI.Page
2
{
3
private
void
Page_Load(
object
sender, System.EventArgs e)
4
{
5
this
.CreateCheckCodeImage(GenerateCheckCode());
6
}
7
8
web 窗体设计器生成的代码
web 窗体设计器生成的代码
#region
web 窗体设计器生成的代码
9
override
protected
void
OnInit(EventArgs e)
10
{
11
//
12
//
CODEGEN: 该调用是 asp.NET web 窗体设计器所必需的。
13
//
14
InitializeComponent();
15
base
.OnInit(e);
16
}
17
18
/**/
/**/
/**/
///
<summary>
19
/**/
///
设计器支持所需的方法 - 不要使用代码编辑器修改
20
/**/
///
此方法的内容。
21
/**/
///
</summary>
22
private
void
InitializeComponent()
23
{
24
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
25
}
26
#endregion
27
28
private
string
GenerateCheckCode()
29
{
30
int
number;
31
char
code;
32
string
checkCode
=
String.Empty;
33
34
System.Random random
=
new
Random();
35
36
for
(
int
i
=
0
; i
<
5
; i
++
)
37
{
38
number
=
random.Next();
39
40
if
(number
%
2
==
0
)
41
code
=
(
char
)(
'
0
'
+
(
char
)(number
%
10
));
42
else
43
code
=
(
char
)(
'
A
'
+
(
char
)(number
%
26
));
44
45
checkCode
+=
code.ToString();
46
}
47
48
Response.Cookies.Add(
new
HttpCookie(
"
CheckCode
"
, checkCode));
49
50
return
checkCode;
51
}
52
53
private
void
CreateCheckCodeImage(
string
checkCode)
54
{
55
if
(checkCode
==
null
||
checkCode.Trim()
==
String.Empty)
56
return
;
57
58
System.Drawing.Bitmap image
=
new
System.Drawing.Bitmap((
int
)Math.Ceiling((checkCode.Length
*
12.5
)),
22
);
59
Graphics g
=
Graphics.FromImage(image);
60
61
try
62
{
63
//
生成随机生成器
64
Random random
=
new
Random();
65
66
//
清空图片背景色
67
g.Clear(Color.White);
68
69
//
画图片的背景噪音线
70
for
(
int
i
=
0
; i
<
25
; i
++
)
71
{
72
int
x1
=
random.Next(image.Width);
73
int
x2
=
random.Next(image.Width);
74
int
y1
=
random.Next(image.Height);
75
int
y2
=
random.Next(image.Height);
76
77
g.DrawLine(
new
Pen(Color.Silver), x1, y1, x2, y2);
78
}
79
80
Font font
=
new
System.Drawing.Font(
"
Arial
"
,
12
, (System.Drawing.FontStyle.Bold
|
System.Drawing.FontStyle.Italic));
81
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
);
82
g.DrawString(checkCode, font, brush,
2
,
2
);
83
84
//
画图片的前景噪音点
85
for
(
int
i
=
0
; i
<
100
; i
++
)
86
{
87
int
x
=
random.Next(image.Width);
88
int
y
=
random.Next(image.Height);
89
90
image.SetPixel(x, y, Color.FromArgb(random.Next()));
91
}
92
93
//
画图片的边框线
94
g.DrawRectangle(
new
Pen(Color.Silver),
0
,
0
, image.Width
-
1
, image.Height
-
1
);
95
96
System.IO.MemoryStream ms
=
new
System.IO.MemoryStream();
97
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
98
Response.ClearContent();
99
Response.ContentType
=
"
image/Gif
"
;
100
Response.BinaryWrite(ms.ToArray());
101
}
102
finally
103
{
104
g.Dispose();
105
image.Dispose();
106
}
107
}
查看全文
相关阅读:
用protobuf编译时报错:protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object file: No such file or directory 的解决方法
编译dubbo2.5.4时遇到的问题及解决
在ubuntu16.04 下安装haproxy 1.5.11 做tcp负载均衡
[原创] zabbix学习之旅七:如何远程操作被监控机器
[原创] zabbix学习之旅五:如何快速搭建一个报警系统
[原创] zabbix学习之旅四:mail客户端安装
[原创] zabbix学习之旅三:agent安装
[原创] zabbix学习之旅二:yum安装
scipy 中关于排列组合的函数
极大似然估计 (二)
原文地址:https://www.cnblogs.com/studio313/p/219469.html
最新文章
rabbitmq简单收发服务搭建
SpringBoot特性
SpringBoot 文件上传临时文件路径问题
Nginx详细安装部署教程
ThreadLocal原理
多线程之倒计时器CountDownLatch和循环栅栏CyclicBarrier
二分查找和数组合并
用Java实现栈结构
简单的链表实现
这几天可能是长时间关注电脑,眼睛没有得到休息,所以就早上起来眼睛有点通
热门文章
这两天本来也就是没有什么事情
今天早上9:40才起来,一直在下着雨
今天早上7:40起来,没有开电脑
前天晚上等同事下班去吃饭到8:00回来
昨天晚上下班的时候等了同事到8:00
好在这天值班没有一个电话,昨天杨已经归还18元
昨天杨装作被鱼刺卡了一直没有问35元负担餐费的事情
虽然和杨住在一起有二十多天了
跟我一起住的同学说是这周要走,可是还是没有动静
如何用jmeter对websockt和protobuf进行压力测试
Copyright © 2011-2022 走看看