title: Using my old membership provider in SharePoint 2010
body: <p>I've got a custom membership provider that I use both in SharePoint 2007 services and in .NET web apps. Now I'm trying to update the SharePoint platform to 2010 Foundation and my provider doesn't work. Below is two examples that both authenticate a user and sets a auth cookie with the same key.</p>
  
  <pre><code>MembershipProvider provider = Membership.Providers["Provider"];
  
  //Alternative one using cookiename (ProviderUserKey from other source then provider)
  if (provider.ValidateUser(user, passwd))
  {
      FormsAuthentication.SetAuthCookie(cookieName, false);
      Response.Redirect("/");
  }
  else
  {
      ShowErrorMsg();
  }
  
  //Alternative two using provider to get ProviderUserKey same as cookieName above
  if (provider.ValidateUser(user, passwd))
  {
      MembershipUser memberUser = provider.GetUser(user, false); //false or true doesnt matter in this provider
      FormsAuthentication.SetAuthCookie(memberUser.ProviderUserKey.ToString(), false);
      Response.Redirect("/");
  }
  else
  {
      ShowErrorMsg();
  }
  </code></pre>
  
  <p>The problem is that SharePoint 2010 uses Claims-based identity and i did try the following but with no success.</p>
  
  <pre><code>MembershipProvider provider = Membership.Providers["Provider"];
  
  if (provider.ValidateUser(user, passwd))
  {
      SPFormsAuthenticationProvider authProvider = IisSetting.FormsClaimsAuthenticationProvider;
  
      SecurityToken token = SPFormsUserNameSecurityTokenHandler.CreateSecurityToken(authProvider.MembershipProvider, cookieName, passwd);
      SPFederationAuthenticationModule.Current.SetPrincipalAndWriteSessionToken(token);
  }
  </code></pre>
  
  <p>But this doesn't work for me. Does anyone know how to base a claims identity on another key then the provided username.</p>