验证码函数;

public string yanzhen()
{
Random r = new Random();
string str = null;
for (int i = 0; i < 5; i++)
{
int number = r.Next(0, 9);
str += number;
}
Bitmap bmp = new Bitmap(120, 50);
Graphics g = Graphics.FromImage(bmp);
for (int i = 0; i < 5; i++)
{
Point p = new Point(i * 19, 0);
string[] font = { "微软雅黑", "仿宋", "黑体", "隶书", "楷书" };
Color[] color = { Color.Green, Color.Brown, Color.Red, Color.Pink, Color.RoyalBlue };
g.DrawString(str[i].ToString(), new Font(font[r.Next(0, 5)], 30, FontStyle.Bold), new SolidBrush(color[r.Next(0, 5)]), p);
}
for (int i = 0; i < 20; i++)
{
Point p1 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
Point p2 = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
g.DrawLine(new Pen(Brushes.Green), p1, p2);
}
for (int i = 0; i < 200; i++)
{
Point p = new Point(r.Next(0, bmp.Width), r.Next(0, bmp.Height));
bmp.SetPixel(p.X, p.Y, Color.Black);
}
pictureBox1.Image = bmp;
return str;
}

时间: 2024-08-01 22:00:56

验证码函数;的相关文章

python随机验证码函数

#验证码函数def yzm(i): code = [] for i in range(i): if i == random.randint(1,3): code.append(str(random.randint(1,9))) else: tmp = random.randint(65,90) code.append(chr(tmp)) return ''.join(code)

简单漂亮的php验证码函数

/* *说明:函数功能是生成验证码 * 参数说明:输入 长度,宽度,高度 */ function vcode($_code_length = 4, $_width = 75, $_height = 25){ $_font=dirname(__FILE__).'/font/Elephant.ttf';//注意字体路径要写对,否则显示不了图片 $_fontsize=$_height/1.8; $_nmsg=""; for($i=0;$i<$_code_length;$i++){ $_

生成随机验证码函数

random def gen_verification_code():     list_veri_code = []     for i in range(0, 6):         rand1 = random.randrange(, )#rand1用来产生随机数,使每一位上的验证码数字和字母随机,randrange函数产生随机数,默认步长为1         if rand1 % 2 == 0:#当随机数为偶数时,该位验证码为数字             num = str(random

随机生成六位验证码函数版(python)

import random def code(n=6,alpha=True): s = '' # 创建字符串变量,存储生成的验证码 for i in range(n): # 通过for循环控制验证码位数 num = random.randint(0,9) # 生成随机数字0-9 if alpha: # 需要字母验证码,不用传参,如果不需要字母的,关键字alpha=False upper_alpha = chr(random.randint(65,90)) lower_alpha = chr(ra

PYDay6- 内置函数、验证码、文件操作

1.内置函数 1.1Python的内置函数 abs() dict() help() min() setattr() all() dir() hex() next() slice() any() divmod() id() object() sorted() ascii() enumerate() input() oct() staticmethod() bin() eval() int() open() str() bool() exec() isinstance() ord() sum() b

inform表单验证,正则表达式,用户名,身份证,密码,验证码

最近利用空闲时间写了部分表单验证,包括用户名,身份证,密码,验证码,仅为自己巩固最近所学的知识 表单的样式使用的是table布局,因为觉得DIV布局定位比较麻烦,table有三列,分别为基本信息,输入的信息,提示信:输入信息栏,插入表单 1 <body> 2 <table> 3 <tr> 4 <td><p>会员名:</p></td> 5 <td><input type="text" n

自己常用JS和JQ 函数

//验证码函数 <button id="send">点击发送验证码</button> <script src="jquery.min.js"></script> <script> $('#send').click(function(){ //发生送验证码函数 //.... time($(this)); }) var wait=60;//时间 function time(o){//o为按钮的对象,p为可选,这

php 简易验证码(GD库)

论坛中为了防止灌水,出现了很多的验证码的插件,现在这里介绍一个非常简单的自定义验证码函数,这个验证码实现的原理就是通过php扩展的gd库来实现的. 给出百度百科对验证码的定义"验证码(CAPTCHA)是"Completely Automated Public Turing test to tell Computers and Humans Apart"(全自动区分计算机和人类的图灵测试)的缩写,是一种区分用户是计算机还是人的公共全自动程序.可以防止:恶意破解密码.刷票.论坛灌

PHP 生成验证码

/** * _code()是验证码函数 * @access public * @param int $_width 表示验证码的长度 * @param int $_height 表示验证码的高度 * @param int $_rnd_code 表示验证码的位数 * @param bool $_flag 表示验证码是否需要边框 * @return void 这个函数执行后产生一个验证码 */function _code($_width = 75,$_height = 25,$_rnd_code =