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

实现一个定制的成员资格提供程序,要求有点奇怪

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

    建立一个新的移动网络平台,供移动用户购买;在他们的手机上下载内容。在过去,我们使用了一种完全定制的登录机制,但我正在研究在下一个版本的平台上使用定制的成员资格提供商。

    只是想通过“是的,会员资格提供商非常适合”或“不,你是在开方便之门”

    1. 用户可能需要使用“手机号码”(用户名)登录&“Pin”(密码) ValidateUser(string username, string password) 方法实现

    2. 用户根本不需要登录。在这种情况下,我们可以透明地将用户跳转到一个特殊的网络运营商网页,当他们透明地返回给我们时,我们将在标题中获得手机号码。在这种情况下,我们需要以编程方式从标题中获取该数字,在代码隐藏中代表他们执行登录(同样没有任何pin/密码),用户将神奇地自动登录。

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

    • 用户仅输入手机(我认为代码隐藏可以满足pin要求)
    • 完全透明的登录(代码隐藏完成整个登录过程)

    任何人对上述内容有任何评论/反馈,或者对您过去所做的任何奇怪的会员资格提供商实现有任何建议。

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

    我认为它可以工作。我们在我们的一个网站上做了#3。下面是我们用来处理它的一段代码。要使用此功能,请创建一个登录页面(transparentlogin.aspx或类似的页面),确保web.config文件允许匿名访问此页面,并在transparentlogin.aspx页面的page_load函数中输入如下代码:

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

    提姆