zoukankan      html  css  js  c++  java
  • 验证码生成

    关于验证码的生成,本人做了一个简单的Demo!

    代码如下:

     1  public class RandomCode
     2     {
     3         /// <summary>
     4         /// 这个是使用字母,数字混合
     5         /// </summary>
     6         /// <param name="VcodeNum"></param>
     7         /// <returns></returns>
     8         public static string CreateRandomCode(int codeCount)
     9         {
    10             string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
    11             string[] allCharArray = allChar.Split(',');
    12             string randomCode = "";
    13             int temp = -1;
    14             Random rand = new Random();
    15             for (int i = 0; i < codeCount; i++)
    16             {
    17                 if (temp != -1)
    18                 {
    19                     rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
    20                 }
    21                 int t = rand.Next(61);
    22                 if (temp == t)
    23                 {
    24                     return CreateRandomCode(codeCount);
    25                 }
    26                 temp = t;
    27                 randomCode += allCharArray[t];
    28             }
    29 
    30             return randomCode;
    31         }
    32     }
    RandomCode

    控制器

    1 [OutputCache(Duration =5)]
    2         public ActionResult Index()
    3         {
    4                                          //设置二维码是几位的
    5             ViewBag.list = RandomCode.CreateRandomCode(6);
    6             return View();
    7         }    

    视图

    1  <p>您的随机验证码为:</p> @ViewBag.list  
  • 相关阅读:
    android前台渲染图片
    Neo4j 无法登录
    缺少less-loader ,版本不易过高
    入门测试,扒拉百度搜索结果
    Selenium 安装注意事项
    测试脚本
    设置 清理 SQL SERVER LOG
    查询SQL server 对象存储信息
    Common.Logging 组件版本兼容问题
    3.启动后端
  • 原文地址:https://www.cnblogs.com/xuan666/p/10739988.html
Copyright © 2011-2022 走看看