I have a website: “https://blahblah.com”
To authenticate to it, I do this (which works fine):
NetworkCredential credentials = new NetworkCredential();
credentials.UserName = AppVars.Username;
credentials.Password = AppVars.Password;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = credentials;
//.....
But how do I go about just validating the username and password if I want to add a login functionality?
UPDATED CODE:
private void btnLogIn_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Username = txtUserName.Text;
Properties.Settings.Default.Password = txtPassword.Text;
using (PrincipalContext pc = new PrincipalContext( ContextType.Domain, AppVars.ixLibraryConnectionTestURL))
{
try
{
bool isValid = false;
isValid = pc.ValidateCredentials(AppVars.Username, AppVars.Password);
if (isValid == true)
{
//just testing
MessageBox.Show("is valid");
}
else
{
//just testing
MessageBox.Show("is not valid");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
the domain name looks something like this: https://xxxxxx-services.zzz999.org/pqg_4/lib/api/sdo/rest/v1
Use: System.DirectoryServices.AccountManagement namespace
You can read more about it here:
http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx