文檔半島外圍網(wǎng)上直營>>telerik中文文檔>>驗證碼提供方
                驗證碼提供方
立即下載Kendo UI for jQuery
本文解釋了如何為Kendo UI Captcha設置服務端提供者,提供程序通過幫助程序類和方法生成并驗證驗證碼。
下面的列表提供了關于重置、音頻和驗證操作的默認請求和響應的信息。
- 
		reset——向服務器發(fā)出GET請求以生成新的Captcha圖像,響應包含新的驗證碼圖像(在下面的代碼片段中—一個返回新圖像的端點)和captchald。
{captcha: "/kendo-ui-dev/captcha/image?captchaid=36967dc7-0ae1-4175-9bb7-9d7f34409889", captchaId: "36967dc7-0ae1-4175-9bb7-9d7f34409889"}
- 
		audio——發(fā)出一個包含驗證碼的GET請求,來自服務器的響應不包含任何參數(shù)而是驗證碼圖像的音頻表示。 
- 
		validate——生成一個包含captchald和用戶在輸入字段中鍵入的文本的GET請求,如果輸入文本與圖像文本匹配則響應為真,如果輸入文本與圖像文本不匹配則響應為假。 
設置
服務端Kendo UI Captcha提供程序與Telerik.Web .Captcha NuGet包一起提供。
安裝Telerik.Web.Captcha NuGet包:
- 右鍵單擊項目并選擇Manage NuGet Packages。
- 確保私有Telerik UI NuGet已配置。
- 搜索并安裝Telerik.Web.Captcha NuGet包。
在c#后端文件或控制器中,添加對以下命名空間的引用:
using System; using System.Drawing.Imaging; using System.IO; using System.Web.Mvc; using Telerik.Web.Captcha;
下面的代碼片段顯示了控制器的基本設置和驗證碼的必要端點:
using System.Drawing.Imaging;
using System.IO;
using System.Web.Mvc;
using Telerik.Web.Captcha;
namespace Kendo.Controllers
{
public class CaptchaController : Controller
{
public ActionResult Reset()
{
CaptchaImage newCaptcha = CaptchaHelper.GetNewCaptcha();
Session["captcha" + newCaptcha.UniqueId] = newCaptcha;
return Json(new
{
captcha = Url.Action("image", "captcha", new { captchaId = newCaptcha.UniqueId }),
captchaId = newCaptcha.UniqueId
}, JsonRequestBehavior.AllowGet);
}
public ActionResult Image(string captchaId)
{
CaptchaImage captcha = (CaptchaImage)Session["captcha" + captchaId];
var image = CaptchaHelper.RenderCaptcha(captcha);
byte[] bmpBytes;
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Png);
bmpBytes = ms.ToArray();
}
return File(bmpBytes, "image/png");
}
public ActionResult Audio(string captchaId)
{
CaptchaImage captcha = (CaptchaImage)Session["captcha" + captchaId];
byte[] bmpBytes;
using (MemoryStream audio = CaptchaHelper.SpeakText(captcha))
{
bmpBytes = audio.ToArray();
}
return File(bmpBytes, "audio/wav");
}
public ActionResult Validate(string captchaId, string captcha)
{
CaptchaImage captchaImage = (CaptchaImage)Session["captcha" + captchaId];
return Json(CaptchaHelper.Validate(captchaImage, captcha.ToUpperInvariant()), JsonRequestBehavior.AllowGet);
}
}
}
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號
渝公網(wǎng)安備
            50010702500608號
             
            
 客服熱線
客服熱線