I am trying to authenticate to SharePoint site using the authentication.asmx web service. The code is as below.
public bool Authenticate()
{
String username = "......";
String password = "......";
Cookie _authCookie;
CookieContainer _cookieContainer;
AuthService.Authentication authentication = new AuthService.Authentication();
authentication.Url = "<web_url>/_vti_bin/Authentication.asmx";
authentication.CookieContainer = new CookieContainer();
authentication.AllowAutoRedirect = true;
authentication.PreAuthenticate = true;
AuthService.LoginResult loginResult = authentication.Login(username, password);
_authCookie = new Cookie();
if (loginResult.ErrorCode == AuthService.LoginErrorCode.NoError)
{
CookieCollection cookies = authentication.CookieContainer.GetCookies(new Uri(authentication.Url));
_authCookie = cookies[loginResult.CookieName];
_cookieContainer = new CookieContainer();
_cookieContainer.Add(_authCookie);
return true;
}
else
return false;
}
But I am getting an error "PasswordNotMatch" in ErrorCode, even though the username and password I am entering is correct.
The AuthService is a Service Reference to the authentication.asmx web service
Did anybody solve the issue?