C#.net制作验证码(英文与数字组成的4位随机数),以及MD5值的使用
原文发布时间为:2008-09-22 —— 来源于本人的百度文章 [由搬家工具导入]
参考资料:http://www.cnblogs.com/gwazy/articles/139510.html
三个窗体:
default1:

属性值:

源码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" Height="35px"
ImageUrl="~/Default2.aspx" ToolTip="看不清图片?点击更换" Width="75px" /><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /></div>
</form>
</body>
</html>
代码:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (string.Compare(TextBox1.Text, Session["checkcode"].ToString(),true)==0)
{
Response.Redirect("~/Default3.aspx");
}
}
}
default2为空窗体:
代码:
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.Drawing;
using System.Drawing.Design;
using System.IO;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Random rd = new Random();
int number;
char code;
string checkcode=string.Empty;
for (int i = 0; i < 4; i++)
{
number = rd.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkcode += code.ToString();
}
Session["checkcode"] = checkcode;
Bitmap bp = new Bitmap(75, 35);
Graphics g = Graphics.FromImage(bp);
g.Clear(Color.White);
for (int i = 0; i < 40; i++)
{
int x1 = rd.Next(bp.Width);
int y1 = rd.Next(bp.Height);
int x2 = rd.Next(bp.Width);
int y2 = rd.Next(bp.Height);
g.DrawLine(new Pen(Color.Aqua), x1, y1, x2, y2);
}
Font ft = new Font("Arial", 18, FontStyle.Bold | FontStyle.Italic);
System.Drawing.Drawing2D.LinearGradientBrush lgb = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, bp.Width, bp.Height), Color.Blue, Color.Blue,10, true);
g.DrawString(checkcode, ft, lgb, 2, 2);
for (int i = 0; i < 80; i++)
{
int x = rd.Next(bp.Width);
int y = rd.Next(bp.Height);
bp.SetPixel(x, y, Color.FromArgb(rd.Next()));
}
g.DrawRectangle(new Pen(Color.Silver), 0, 0, bp.Width-1 , bp.Height-1 );
MemoryStream ms = new MemoryStream();
bp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
//Response.ClearContent();
//Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
g.Dispose();
ms.Dispose();
ms.Close();
}
}
default3为空窗体(MD5值的使用):
代码:
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string md5= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Session["checkcode"].ToString(),"MD5");
Response.Write(md5);
}
}
C#.net制作验证码(英文与数字组成的4位随机数),以及MD5值的使用的更多相关文章
- Java实现随机生成由字母、数字组合的N位随机数
通过Math.random函数生成所需的字符所有序列,通过判断当前字符是否属于大小写.数字,符合者加入数组内,直到数组存储N位为止,最后把当前数组转为字符串返回调用处. /** * 随机生成由数字.字 ...
- JAVAWEB项目实现验证码中文、英文、数字组合
验证码基础 一.什么是验证码及它的作用 :验证码为全自动区分计算机和人类的图灵测试的缩写,是一种区分用户是计算机的公共全自动程序,这个问题可以由计算机生成并评判,但是必须只有人类才能解答.可以防止恶意 ...
- (一)学习MVC之制作验证码
制作验证码的方法在@洞庭夕照 看到的,原文链接:http://www.cnblogs.com/mzwhj/archive/2012/10/22/2720089.html 现自己利用该方法制作一个简单的 ...
- Jsp制作验证码
验证码 验证码(CAPTCHA)是"Completely Automated Public Turing test to tell Computers and Humans Apart&qu ...
- js控制文本框只能输入中文、英文、数字与指定特殊符号.
先在'' 里输入 onkeyup="value=value.replace(/[^\X]/g,'')" 然后在(/[\X]/g,'')里的 X换成你想输入的代码就可以了, 中文u4 ...
- (js) 输入框只能输入中文、英文、数字、@符号和.符号
只能输入中文.英文.数字.@符号和.符号<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0 ...
- 解决英文或数字在HTMl网页中不自动换行。
对于网页设计的新手而言,在接触一段时间的HTML/CSS后,一定会遇到这样的问题:对于已经定义了宽度的容器(如DIV,TD,段落等)如果里面出现了较长的英文或数字,则内容不能自动换行然后会将框架撑出设 ...
- EXCEL表格单元格中包含数字英文和汉字,如何自动去掉汉字,保留英文和数字
EXCEL表格单元格中包含数字英文和汉字,如何自动去掉汉字,保留英文和数字 Function 求数字和字母(对象 As String) '在文本与数字混杂中提取数字和字母 Dim myReg ...
- JS 控制文本框只能输入中文、英文、数字与指定特殊符号
想做姓名输入的js判断是否是中文,但是网上找的很多是源于一篇文章的,判断中文的正则式不对,后来找到一个可以准确判断了,但是是监测里面有中文的就行,跟我想要的只能输入中文的意思相左,所以又找了下面的 J ...
随机推荐
- The expected type was 'System.Int64' but the actual value was null.”
System.InvalidOperationException:“An exception occurred while reading a database value for property ...
- 使用jsp读取某个目录下的所有文件名,并保存在json文件中
<%@page import="java.io.File"%> <%@page import="java.io.FileWriter"%> ...
- knn算法之预测数字
训练算法并对算法的准确值准确率进行估计 #导入相应模块 import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%mat ...
- [图文] Fedora 28 使用 Virt-Manager 创建 KVM 虚拟机以及 配置 KVM 虚拟机
实验说明: 往后的许多实验都将以Linux平台下的 KVM虚拟机为主,所以不可少的就是 Virt-Manager 虚拟机管理器. 本章将对如何安装和使用Virt-Manager管理器进行讲解,并且会对 ...
- 微信JS-SDK 示例
微信JS-SDK 示例 1.html部分 <!DOCTYPE html> <!-- saved from url=(0028){sh:$selfUrl} --> <htm ...
- Python基础——字符串操作
运算符 加(+) str2="hello"+"python" print(str2) 乘(*) str1="hello python" ...
- (转)rvm安装与常用命令
rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换. https://rvm.io/ 如果你打算学习ruby/rails, rvm是必不可少的工具之一. 这里所有的命令都是再用户 ...
- LeetCode(129) Sum Root to Leaf Numbers
题目 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a num ...
- nrf52810学习笔记——二
nrf52810为nordic支持蓝牙 5.0性价比最高的一款芯片,不过这个芯片的rom不得不吐槽下,只有192KB,不知道为什么定了个192,而不是大家所熟悉的256KB,估计价格是个原因吧,15. ...
- 二叉排序树:POJ2418-Hardwood Species(外加字符串处理)
Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Description Hardwoods are the botanical gr ...