c# - Authenticating to AD using sAMAccountName format using PrincipleContext -



c# - Authenticating to AD using sAMAccountName format using PrincipleContext -

i implementing advertisement authentication offline application.

my original code did following:

var validauth = false; using (var context = new system.directoryservices.accountmanagement.principalcontext(system.directoryservices.accountmanagement.contexttype.domain)) { validauth = context.validatecredentials(_viewmodel.username, txtpassword.password); }

however, during testing noticed caused business relationship lockouts in half number of attempts of advertisement grouping policy - policy set 4 attempts before lockout, user locked out in 2.

i googled , found article on msdn , tl;dr this:

it sounds bad password count increment 2 if utilize upn format (domain@samaccountname), however, count increment 1 every time if utilize samaccountname format (domain\samaccountname).

in lite of changed code this:

var validauth = false; using (var context = new system.directoryservices.accountmanagement.principalcontext(system.directoryservices.accountmanagement.contexttype.domain)) { var usernametoauth = string.format("{0}\\{1}", environment.userdomainname, _viewmodel.username); validauth = context.validatecredentials(usernametoauth, txtpassword.password); }

but fails authenticate regardless of input. if alter utilize old style upn format of user@domain authenticates fine - using 2 authentication requests.

the msdn post says utilize samaccountname format work around struggling work out how this. original code didn't explicitly utilize old upn format - passed user name straight validatecredentials method (no @ symbol anywhere seen) method utilize old upn method first?

any advice please - don't particularly want half bad log on attempts our users can have.

i used domain specification in principalcontext constructor, specified in post, that:

public static bool isauthenticated(string username_, string password_) { using (var pc = new principalcontext(contexttype.domain, domainmanager.domainname)) homecoming pc.validatecredentials(username_, password_); }

in case, utilize system.directoryservices.activedirectory.domain , system.directoryservices.activedirectory.domaincontroller domainmanager.domainname values.

c# .net authentication active-directory windows-authentication

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -