public User RegisterUser(string email, string password)
        {
            MembershipCreateStatus status;
            User user = new User();
            user.IsAuthenticated = false;

            Membership.CreateUser(email, password, email,Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), true, out status);
            if (status == MembershipCreateStatus.Success)
            {
                MembershipUser newlyCreatedUser = Membership.GetUser(email);
                user.AuthenticationToken = newlyCreatedUser.ProviderUserKey.ToString();
                user.Email = email;
                user.IsAuthenticated = true;
            }
            else
            {
                switch (status)
                {
                    case MembershipCreateStatus.DuplicateEmail:
                        throw new InvalidOperationException("There is already a user with this email address.");
                    case MembershipCreateStatus.DuplicateUserName:
                        throw new InvalidOperationException("There is already a user with this email address.");
                    case MembershipCreateStatus.InvalidEmail:
                        throw new InvalidOperationException("Your email address is invalid");
                    case MembershipCreateStatus.InvalidPassword:
                        throw new InvalidOperationException("Your password is invalid");
                    default:
                        throw new InvalidOperationException("There was a problem creating your account. Please try again.");
                }
            }
            return user;
        }
 public User GetUserDetailsFrom(string token)
 {
     User user = new User();
     string parameters = String.Format("apiKey={0}&token={1}&format=xml", ApplicationSettingsFactory.GetApplicationSettings().JanrainApiKey, token);
     string response;
     using (var w = new WebClient())
     {
         response = w.UploadString("https://rpxnow.com/api/v2/auth_info", parameters);
     }
     var xmlResponse = XDocument.Parse(response);
     var userProfile = (from x in xmlResponse.Descendants("profile")
                        select new
                        {
                            id = x.Element("identifier").Value,
                            email = (string)x.Element("email") ?? "No Email"
                        }).SingleOrDefault();
     if (userProfile != null)
     {
         user.AuthenticationToken = userProfile.id;
         user.Email = userProfile.email;
         user.IsAuthenticated = true;
     }
     else
         user.IsAuthenticated = false;
     return user;
 }
 public User Login(string email, string password)
 {
     User user = new User();
     user.IsAuthenticated = false;
     if (Membership.ValidateUser(email, password))
     {
         MembershipUser validatedUser = Membership.GetUser(email);
         user.AuthenticationToken = validatedUser
         .ProviderUserKey.ToString();
         user.Email = email;
         user.IsAuthenticated = true;
     }
     return user;
 }