ASP.NET(c#)语音验证码制作(附源代码)
2009-11-27 16:52:15 来源:WEB开发网核心提示:最近发现语音验证码越来越流行,比如有次在注册Gmail邮箱看到过,ASP.NET(c#)语音验证码制作(附源代码),还有msn页面也有语音验证码,还有国外一些网站等,这里包括头部begin.mp3和尾部end.mp3view plaincopy to clipboardprint?Response.ContentTyp
最近发现语音验证码越来越流行,比如有次在注册Gmail邮箱看到过,还有msn页面也有语音验证码,还有国外一些网站等。
花时间研究了下,语音验证码主要跟一般验证码的区别就在于如何让验证码播放。本文语音验证码原理:从服务器生成验证码,
并保存到cookie中(getcode.aspx.cs),当点收听验证码的时候,调用javascirpt操作(这里使用jquery)cookie读取验证码,
然后把验证码传到codevoice.aspx页,然后按顺序把验证码合成生成一个mp3文件,最后把这个文件传入Flash中播放,
你将收听的声音为:“当前验证码是5678请输入”。这个原理也是大部分网站使用的语音验证码原理类似。
源码下载:下载 (请使用VS2008 SP1或VS2010打开)
页面上放置验证码图片页面代码
view plaincopy to clipboardPRint?
<form id="form1" runat="server">
<div>
<input type="text" name="txtCode" id="txtCode" maxlength="8" />
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,换一张" title="看不清楚,换一张" />
<img id="imgRead" src=http://www.cncms.com/"image/maintb.gif" mce_src=http://www.cncms.com/"image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="playvoice('player');" />
<span id="player"></span>
</div>
</form>
<form id="form1" runat="server">
<div>
<input type="text" name="txtCode" id="txtCode" maxlength="8" />
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,换一张" title="看不清楚,换一张" />
<img id="imgRead" src=http://www.cncms.com/"image/maintb.gif" mce_src=http://www.cncms.com/"image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="playvoice('player');" />
<span id="player"></span>
</div>
</form>
点收听验证码时调用的js函数如下:
view plaincopy to clipboardprint?
function playvoice(id) {
var voiceid = document.getElementById(id);
var voicecode = $.cookie('ValidateCode');
voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + "" mce_src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + ""
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptaccess='always'
ype='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}
function playvoice(id) {
var voiceid = document.getElementById(id);
var voicecode = $.cookie('ValidateCode');
voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + "" mce_src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + ""
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptAccess='always'
type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}
其中$.cookie('ValidateCode')是读取cookie验证码,这里使用了一个jquery操作cookie插件
生成mp3页面代码如下:
//读取验证码生成mp3,这里包括头部begin.mp3和尾部end.mp3
view plaincopy to clipboardprint?
Response.ContentType = "audio/mpeg";
Response.WriteFile("sound/begin.mp3");
string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";
if (checkCode.Length > 0)
for (int i = 0; i < checkCode.Length; i++)
{
Response.WriteFile("sound/"+checkCode[i] + ".mp3");
}
Response.WriteFile("sound/end.mp3");
Response.ContentType = "audio/mpeg";
Response.WriteFile("sound/begin.mp3");
string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";
if (checkCode.Length > 0)
for (int i = 0; i < checkCode.Length; i++)
{
Response.WriteFile("sound/"+checkCode[i] + ".mp3");
}
Response.WriteFile("sound/end.mp3");
【本文作者分别在cnblogs,csdn,http://www.Ajaxcn.net同步发布,转载请保留此说明】
flash播放代码主要在第一帧关键帧右击动作,插入以下代码根据传入的播放数字mp3地址
view plaincopy to clipboardprint?
var mysound = new Sound();
var mysong = url;
var isPlay = 1;
var intnum:Number = setInterval(playSong, 500);
function playSong() {
if (isPlay == 1) {
mysound.loadSound(mysong+"?code="+code, true);
mysound.start();
clearInterval(intnum);
isPlay = 0;
}
}
花时间研究了下,语音验证码主要跟一般验证码的区别就在于如何让验证码播放。本文语音验证码原理:从服务器生成验证码,
并保存到cookie中(getcode.aspx.cs),当点收听验证码的时候,调用javascirpt操作(这里使用jquery)cookie读取验证码,
然后把验证码传到codevoice.aspx页,然后按顺序把验证码合成生成一个mp3文件,最后把这个文件传入Flash中播放,
你将收听的声音为:“当前验证码是5678请输入”。这个原理也是大部分网站使用的语音验证码原理类似。
源码下载:下载 (请使用VS2008 SP1或VS2010打开)
页面上放置验证码图片页面代码
view plaincopy to clipboardPRint?
<form id="form1" runat="server">
<div>
<input type="text" name="txtCode" id="txtCode" maxlength="8" />
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,换一张" title="看不清楚,换一张" />
<img id="imgRead" src=http://www.cncms.com/"image/maintb.gif" mce_src=http://www.cncms.com/"image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="playvoice('player');" />
<span id="player"></span>
</div>
</form>
<form id="form1" runat="server">
<div>
<input type="text" name="txtCode" id="txtCode" maxlength="8" />
<img onclick="this.src='getcode.aspx';" src="getcode.aspx" mce_src="getcode.aspx" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="看不清楚,换一张" title="看不清楚,换一张" />
<img id="imgRead" src=http://www.cncms.com/"image/maintb.gif" mce_src=http://www.cncms.com/"image/maintb.gif" align="absmiddle" style="cursor: pointer" mce_style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="playvoice('player');" />
<span id="player"></span>
</div>
</form>
点收听验证码时调用的js函数如下:
view plaincopy to clipboardprint?
function playvoice(id) {
var voiceid = document.getElementById(id);
var voicecode = $.cookie('ValidateCode');
voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + "" mce_src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + ""
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptaccess='always'
ype='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}
function playvoice(id) {
var voiceid = document.getElementById(id);
var voicecode = $.cookie('ValidateCode');
voiceid.innerHTML = "<embed id='sound_play' name='sound_play' src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + "" mce_src=http://www.cncms.com/"sound_play.swf?" + (new Date().getTime()) + ""
FlashVars='isPlay=1&url=codevoice.aspx&code=" + voicecode + "' width='0' height='0' allowScriptAccess='always'
type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></embed>";
}
其中$.cookie('ValidateCode')是读取cookie验证码,这里使用了一个jquery操作cookie插件
生成mp3页面代码如下:
//读取验证码生成mp3,这里包括头部begin.mp3和尾部end.mp3
view plaincopy to clipboardprint?
Response.ContentType = "audio/mpeg";
Response.WriteFile("sound/begin.mp3");
string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";
if (checkCode.Length > 0)
for (int i = 0; i < checkCode.Length; i++)
{
Response.WriteFile("sound/"+checkCode[i] + ".mp3");
}
Response.WriteFile("sound/end.mp3");
Response.ContentType = "audio/mpeg";
Response.WriteFile("sound/begin.mp3");
string checkCode = HttpContext.Current.Request.QueryString["code"].ToString();// string checkCode ="8888";
if (checkCode.Length > 0)
for (int i = 0; i < checkCode.Length; i++)
{
Response.WriteFile("sound/"+checkCode[i] + ".mp3");
}
Response.WriteFile("sound/end.mp3");
【本文作者分别在cnblogs,csdn,http://www.Ajaxcn.net同步发布,转载请保留此说明】
flash播放代码主要在第一帧关键帧右击动作,插入以下代码根据传入的播放数字mp3地址
view plaincopy to clipboardprint?
var mysound = new Sound();
var mysong = url;
var isPlay = 1;
var intnum:Number = setInterval(playSong, 500);
function playSong() {
if (isPlay == 1) {
mysound.loadSound(mysong+"?code="+code, true);
mysound.start();
clearInterval(intnum);
isPlay = 0;
}
}
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接