【问题标题】:ServiceStack Authentication validation with Captcha使用 Captcha 进行 ServiceStack 身份验证验证
【发布时间】:2013-05-09 08:58:43
【问题描述】:

我想在身份验证提交表单api/auth/credentials 中添加一个验证码字段。

所以,除了 usernamepasswordrememberme 之外,现在表单需要包含 captcha 字段.

然后,我将检查存储验证码图像答案的会话与提交的验证码结果的表单。

我的问题是,我需要覆盖 SS 源代码的哪些部分才能正确执行?

我的感觉是我应该一开始就考虑覆盖和自定义 CredentialsAuthProvider 类?

【问题讨论】:

    标签: c# servicestack


    【解决方案1】:

    这是一个快速的方法:

        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
            }; 
        }
    

    期待看到你们向我展示更优雅/高效/可扩展的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2014-07-25
      相关资源
      最近更新 更多