您的位置:首页 > 其它

仿QQ注册验证码的实现。

2016-03-31 15:51 211 查看
最近发现一些网站的验证码全部换成了“极验”和“点触”的,发现QQ的注册也是与“点触”的相似。就想尝试实现一个。

先上效果图:

public bool Validate(dynamic pos)
{
bool isValidate = false;
_httpContext.Session["VCode_ISValidate"] = false;
if (pos.Length > 0 && _httpContext.Session["VCode_Word"] != null)
{
bool isNotMath = false;
List<WordPos> verWordList = (List<WordPos>)_httpContext.Session["VCode_Word"];
_httpContext.Session["VCode_ISValidate"] = true;
_httpContext.Session["VCode_Word"] = null;

if (pos.Length == verWordList.Count)
{
for (int i = 0; i < pos.Length; i++)
{
var _posLeft = Convert.ToInt32(pos[i]["left"]) + 20 / 2;
var _posTop = Convert.ToInt32(pos[i]["top"]) + 23 / 2;
Point _posCenter = new Point(_posLeft, _posTop);

var _ckLeft = Convert.ToInt32(verWordList[i].X + verWordList[i].Width / 2);
var _ckTop = Convert.ToInt32(verWordList[i].Y + verWordList[i].Height / 2);

Point _ckPosCenter = new Point(_ckLeft, _ckTop);

if (Utils.GetDistance(_posCenter, _ckPosCenter) > 23)
{
isNotMath = true;
break;
}
}
if (isNotMath == false)
{
isValidate = true;
}
}
}
return isValidate;
}


View Code

当然,实际上QQ注册的需要验证字都是一个词组,要做到这一点可能只有做一个词库才能完成了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: