验证码的作用是为了防止物理盗号,或者暴力破坏服务器
图片验证码生成
模型的实现
首先在Models文件夹添加实现验证码的模型CreateValidateCode
public class CreateValidateCode
{
private string CreateRandomCode(int codeCount)
{
string code = "";
Random r = new Random();
//偶数给数字,奇数给小写字母
for (int i = 0; i < codeCount; i++)
{
//小写字母和数字
int type = r.Next(100);
if (type % 2 == 0)
{
code += r.Next(0, 10);
}
else
{
code += (char)r.Next(97, 123);
}
}
return code;
}
/// <summary>
/// 生成验证码
/// </summary>
/// <param name="codeCount"