代码之家  ›  专栏  ›  技术社区  ›  Eoin Campbell

实现具有稍微奇怪要求的自定义会员提供程序

  •  2
  • Eoin Campbell  · 技术社区  · 16 年前

    构建一个新的移动网络平台,供移动用户购买和使用;在手机上下载内容。过去,我们使用了一种完全定制的登录机制,但我正在研究在平台的下一个版本中使用自定义会员提供程序。

    问题是,我们有一些稍微奇怪的“登录”机制要求,所以我不能100%确定会员资格提供者是最合适的。

    需求

    1. 用户可能需要使用“手机号码”(用户名)和;“Pin”(密码) 这非常合适,因为他们已经注册并通过短信确认,这满足了 ValidateUser(string username, string password)

    2. 用户可能只需要使用“手机号码”登录。在这种情况下,我们不会费心进行身份验证。它减少了用户的步骤数,当我们尝试向特定操作员收费时,会由他们进行验证。(运营商可以验证输入的手机号码是否与手机在访问运营商支付网站时匹配)。..所以即使用户有密码,我们也需要以某种方式欺骗会员提供者,让他们用空白密码进入。

    要求2和;3有点奇怪。我们基本上有三种不同的登录机制,一个会员提供者需要满足这些机制。

    • 用户输入手机和;用户输入的Pin码
    • 完全透明登录(代码隐藏完成整个登录过程)

    1 回复  |  直到 16 年前
        1
  •  1
  •   CodeThug    16 年前

    const string specialpassword = "ThisIsOurSpecialPasswordForBehindTheScenesLogin";
    
    if (MobileNumberFoundInHeader())
    {
      string username = GetMobileNumberFromHeaders();
      // Authenticate the user behind the scenes
      System.Web.Security.FormsAuthentication.SetAuthCookie(username, false);
      System.Web.Security.FormsAuthentication.Authenticate(username, specialpassword);
    }
    else
    {
      throw new Exception ("Mobile Number Missing");
    }
    

    然后,在MembershipProvider的ValidateUser函数中,确保执行以下检查:

    public override bool ValidateUser(string username, string password)
    {
     const string specialpassword = "ThisIsOurSpecialPasswordForBehindTheScenesLogin";
    
     bool ValidationSuccess = false;
    
     // If the password being passed in is the right secret key (same  
     // for all users), then we will say that the password matches the
     // username, thus allowing the user to login 
     if (password == specialpassword)
     {
       ValidationSuccess = true;
     }
    
     if (DoStandardUsernamePasswordVerification() == true)
     {
       ValidationSuccess = true;
     }
    
     return ValidationSuccess;
    }
    

    对于需求#2,我感到有些困惑。究竟什么是操作员?我以为我们在处理一部使用网络浏览器浏览网站的手机。操作员在哪里?如果我上面提出的解决方案没有帮助,请发布一个回复,提供有关运营商的更多详细信息。