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

时间:2009-05-27 11:04:23

标签: asp.net asp.net-membership membership-provider mobile-website

为移动用户构建新的移动网络平台以购买&在手机上下载内容。在过去,我们使用了完全定制的登录机制,但我正在调查使用自定义成员资格提供程序来进行下一版本的平台。

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

只是寻找一些关于以下要求的一般反馈,“是的,会员提供商是一个很好的选择”或“不,你是在一个圆孔敲打方形钉”

要求

  1. 用户可能需要使用“手机号码”(用户名)& “Pin”(密码) 这很合适,因为他们已经注册并通过短信确认,并且满足ValidateUser(string username, string password)方法实施

  2. 用户可能需要仅使用“手机号码”登录。在这种情况下,我们不打扰在我们身边进行身份验证。它减少了用户的步骤数,并在我们尝试对其进行计费时由特定操作员进行验证。 (运营商可以验证输入的手机号码,当它到达运营商支付网站时与手机匹配)...所以即使用户有密码,我们也需要在某种程度上欺骗会员提供商,让他们进入密码空白。

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

    < / LI>

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

    • 用户进入手机&amp;用户输入Pin
    • 用户仅进入移动设备(我认为代码落后于满足引脚要求)
    • 完全透明的登录(完成整个登录过程的代码)

    任何人都对上述内容有任何意见/反馈或对您过去所做的任何奇怪的会员提供商实施有任何建议。

1 个答案:

答案 0 :(得分:1)

我认为它可行。我们在其中一个网站上做#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;
}

至于要求#2,我有点困惑。究竟什么是运营商?我以为我们正在处理使用网络浏览器浏览网站的手机。操作员在哪里适合?如果我上面提出的解决方案没有帮助,请发布回复,其中包含有关运营商的更多详细信息。