Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Understanding custom authentication code

$
0
0

I am new into web api authentication and i require little assistance in understanding the following method below of an example web api:

private bool TryGetPrincipal(string username, string password, out IPrincipal principal)
        {
            // this is the method that does the authentication
            //users often add a copy/paste space at the end of the username
            username = username.Trim();
            password = password.Trim();Person person = AccountManagement.ApiLogin(username, password);
            if (person != null)
            {
                // once the user is verified, assign it to an IPrincipal with the identity name and applicable roles
                principal = new GenericPrincipal(new GenericIdentity(username), System.Web.Security.Roles.GetRolesForUser(username));
                return true;
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(username))
                {
                    log.Error("Failed to login: username=" + username + "; password=" + password);
                }
                principal = null;
                return false;
            }
        }

I would like to seek understanding in, what methods would 'Person' class consists of. I would also like to know what the following line mean:

Person person = AccountManagement.ApiLogin(username, password);

Any examples or suggestion would be very much appreciated.  

Many thanks


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>