Aspx页面设计源代码
<%@Page Language="VB"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default" %>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script language="vbscript"type="text/vbscript">
// <!CDATA[
// ]]>
</script>
<script language="javascript"type="text/javascript">
// <!CDATA[
// ]]>
</script>
</head>
<body>
<form id="form1"runat="server">
<div>
 
<asp:Label ID="Label1"runat="server"Style="z-index: 100; left: 24px; position: absolute;            top: 72px"Text="验证码"></asp:Label>
   
<asp:Label ID="Label3"runat="server"Style="z-index: 101; left: 24px; position: absolute;            top: 120px"Text="验证码"></asp:Label>
<img src="localhost:2115/WebSite4/Default2.aspx?tmp=1"alt="验证码获取失败"id="IMG1"onclick="return
IMG1_onclick()"/>
  
<asp:Label ID="Label2"runat="server"Style="z-index: 102; left: 280px; position: absolute;            top: 72px"Text="请输入验证码,不区分大小写"></asp:Label>
 
<asp:TextBox ID="TextBox1"runat="server"Style="z-index: 103; left: 96px; position: absolute;
top: 72px"></asp:TextBox>
 
<asp:Button ID="Button1"runat="server"Style="z-index: 106; left: 136px; position: absolute;
top: 168px"Text="确定"/>
</div>
</form>
</body>
</html>
Aspx后台设计源代码
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = Request.Cookies("name").Value.ToString() '从cookies中接收随机字符串
s = s.ToLower() '转换为小写自符
If TextBox1.Text.ToLower = s Then
MsgBox("succeed")
Else : MsgBox("failed")
End If'判断是否正确
End Sub
End Class
随即图形生成源代码
Partial Class Default2
Inherits System.Web.UI.Page
Public s As String = ""'随即验证码字符形式
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear() '清除返回缓存流
'随机数产生过程()
Dim number1 As Integer'for语句将用到的变量
Dim number2 As Integer
number2 = 4 '要生成几个字符的验证码便赋值几
Dim random As New Random '新建随机生成器
Dim number3 As Integer'‘用于保存随机产生的数值
For number1 = 1 To number2
number3 = random.Next(62) '定义随机数上界
Select Case number3
Case 0
s = s + "0"
Case 1
s = s + "1"
Case 2
s = s + "2"
Case 3
s = s + "3"
Case 4
s = s + "4"
Case 5
s = s + "5"
Case 6
s = s + "6"
Case 7
s = s + "7"
Case 8
s = s + "8"
Case 9
s = s + "9"
Case 10
s = s + "A"
Case 11
s = s + "B"
Case 12
s = s + "C"
Case 13
s = s + "D"
Case 14
s = s + "E"
Case 15
s = s + "F"
Case 16
s = s + "G"
Case 17
s = s + "H"
Case 18
s = s + "I"
Case 19
s = s + "G"
Case 20
s = s + "K"
Case 21
s = s + "L"
Case 22
s = s + "M"
Case 23
s = s + "N"
Case 24
s = s + "O"
Case 25
s = s + "P"
Case 26
s = s + "Q"
Case 27
s = s + "R"
Case 28
s = s + "S"
Case 29
s = s + "T"
Case 30
s = s + "U"
Case 31
s = s + "V"
Case 32
s = s + "W"
Case 33
s = s + "X"
Case 34
s = s + "Y"
Case 35
s = s + "Z"
Case 36
s = s + "a"
Case 37
s = s + "b"
Case 38
s = s + "c"
Case 39
s = s + "d"
Case 40
s = s + "e"
Case 41
s = s + "f"
Case 42
s = s + "g"
Case 43
s = s + "h"
Case 44
s = s + "i"
Case 45
s = s + "g"
Case 46
s = s + "k"
Case 47
s = s + "l"
Case 48
s = s + "m"
Case 49
s = s + "n"
Case 50
s = s + "o"
Case 51
s = s + "p"
Case 52
s = s + "q"
Case 53
s = s + "r"
Case 54
s = s + "s"
Case 55
s = s + "t"
Case 56
s = s + "u"
Case 57
s = s + "v"
Case 58
s = s + "w"
Case 59
s = s + "x"
Case 60
s = s + "y"
Case 61
asp网页源码
s = s + "z"
End Select
Next
'图形生成过程
Dim bmp As New System.Drawing.Bitmap("bmp")
Dim bmp1 As New System.Drawing.Bitmap(100, 30,
System.Drawing.Imaging.PixelFormat.Format24bppRgb)
System.Drawing.Graphics.FromImage(bmp1)
Dim gra1 As System.Drawing.Graphics
gra1 = System.Drawing.Graphics.FromImage(bmp1)
gra1.Clear(Drawing.Color.White)
gra1.DrawString(s, New System.Drawing.Font("Verdana", 18), Drawing.Brushes.Blue, 0, 0)        gra1.Save()
System.Drawing.Graphics.FromImage(bmp)
Dim gra As System.Drawing.Graphics
Dim x '临时变量
Dim y '监时变量
Dim w = 100 '验证图的宽度
Dim h = 30 '验证图的高度
Dim al  'alpha
Dim rl  'red
Dim gl  'Green
Dim bl  'Blue
For x = 1 To w - 1
For y = 1 To h - 1
al = bmp1.GetPixel(x, y).A
rl = bmp1.GetPixel(x, y).R
gl = bmp1.GetPixel(x, y).G
bl = bmp1.GetPixel(x, y).B
al = 70
If (rl - 50 > 0) Then
rl = rl - 50
End If
If (gl - 50 > 0) Then
gl = gl - 50
End If
If (bl - 50 > 0) Then
bl = bl - 50
End If
gra = System.Drawing.Graphics.FromImage(bmp)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。