lxhdj
lxhdj插画画廊
uid: 313858
级别: 新手上路
精华: 0
发帖: 1
威望: 9 点
积分: 8 分
推广值: 0 点
注册时间:2008-06-17
最后登陆:2009-02-13
|
验证码生成算法
AS3 实现: flash: http://uploadingit.com/files/691838_satjj/randomCode.swf
用法: var code:String=verificationCode.getCode(length);
算法: class verificationCode{ public static function getCode(len:uint):String{ var code:String=""; for(var i:uint=0; i<len; i++){ code+=getRandomChar(); } return code; } public static function getRandomChar():String{ // ASCII values: // 0-9: 48-57 // A-Z: 65-90 // a-z: 97-122 // Generate a random integer between 0 and 61, both inclusive. // Values from 0 to 9 will remain as numbers, // while values from 10 to 35 and from 36 to 61 will be mapped to // alphabets from A-Z and a-z respectively.
var rdm:uint=Math.floor(Math.random()*62); if(rdm<10){ return String(rdm); } else if(rdm<36){ return String.fromCharCode(rdm+55); } else { return String.fromCharCode(rdm+61); } } }
附演示源文件:http://uploadingit.com/files/691837_c7i6q/code.zip
|
lxhdj插画画廊 http://chahua.com/u/313858 http://cg.chahua.org 中国插画画廊-插画师作品展示中心
|
[1 楼]
|
Posted:2008-06-27 02:14| |
| |