使用Captcha进行身份验证
本文关键字:身份验证 Captcha 使用 | 更新日期: 2023-09-27 18:12:20
我想在认证提交表单api/auth/credentials
中添加一个CAPTCHA字段。
然后,我将检查存储验证码图像的答案的会话与表单提交的验证码结果。
我的问题是,SS源代码的哪一部分我需要重写才能正确地做到这一点?
我的感觉是,我应该看看覆盖和自定义CredentialsAuthProvider类的开始?
这里有一个快速的方法:
public ExtDeskResponse Post(MyAuth req) {
//Captcha Validation
var valid = req.Captcha == base.Session.Get<Captcha>("Captcha").result;
//SS Authentication
var authService = AppHostBase.Instance.TryResolve<AuthService>();
authService.RequestContext = new HttpRequestContext(
System.Web.HttpContext.Current.Request.ToRequest(),
System.Web.HttpContext.Current.Response.ToResponse(),
null);
var auth = string.IsNullOrWhiteSpace(
authService.Authenticate(new Auth {
UserName = req.UserName,
Password = req.Password,
RememberMe = req.RememberMe,
}).UserName);
if (valid && auth) {
//...logic
}
return new MyAuthResponse() {
//...data
};
}