using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
namespace SessionCode
{
public partial class checkimage : System.Web.UI.Page
{
/// <summary>
/// 驗證碼產生程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
GetCode();
}
//產生code
protected void GetCode()
{
System.Random rand = new Random();
int len = 4; //這裡設置驗證碼長度,我的定義為4,最近見到些網上上有隨機4,5,6位的。這裡自己寫個隨機函數就可以了。
char[] chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
System.Text.StringBuilder myStr = new System.Text.StringBuilder();
for (int iCount = 0; iCount < len; iCount++)
{
myStr.Append(chars[rand.Next(chars.Length)]);
}
string text = myStr.ToString();
// 保存驗證碼到 session 中以便其他模塊使用
Session["code"] = text; //這裡你的登陸頁面判斷輸入驗證碼是否正確,if (txtCode.text == Session["code"]) 正確讀庫檢索User/Password,不正確彈窗。自己寫
Size ImageSiz