1
votes

I am trying to authenticate the users login against Active Directory, but I am not using the popup Active Directory box, all I am doing is passing the data through when I do the get request to the API. How would I authenticate it because all I know how to do with c# is return a string and bool.

Please help me.

Right now I'm just returning true when someone calls the function how would I go about checking the data correctly and returning a bool to match the answer it gets.

public class AuthController : ApiController
{
    // GET api/auth/Uname+Pword
    public bool Get(string Uname, string Pword)
    {
        return true;
    }
}
1
For a start it's not necessarily safe to pass the username and password as strings to the controller. That aside you should read some authentication tutorials, like this one. docs.microsoft.com/en-us/azure/active-directory/develop/… What you have asked for is a solution that could have varying implications that we wouldn't knowJonE

1 Answers

2
votes

Authenticate using LDAP in C# is keyword for you.

using(var context = new PrincipalContext(ContextType.Domain, "mydomain", "mydomain\serviceAcct", "serviceAcctPass")) {
 //Username and password for authentication.
 return context.ValidateCredentials(username, password); 
}