Search code examples
asp.net-mvcsimplemembership

How do I manually "log a user in" using WebSecurity + SimpleMembership?


I'd like to use WebSecurity+SimpleMembership, but implement the ability to (optionally) login users via a custom/alternative authentication method.

WebSecurity.Login only has one method signature, which requires both a username and a password. I'd like to skip the password check, e.g.:

if (MyCustomAuthenticationMethod.Authenticate(username, customData)) {
    WebSecurity.Login(username); // Login without password check, method doesn't exist though
}

I assume custom-auth-methods are possible given OAuthWebSecurity exists, but I'm not sure how to go about implementing my own.


Solution

  • Well, you could simply go back to root of authentication and call directly

    FormsAuthentication.SetAuthCookie
    

    This will create cookie and authenticate your user. See Asp.net Memebership Authorization without password