Hi,
I am using a method that has the following signature:
public static bool TryAuthenticate(string userName, string password,
string domainName, out AuthenticationFailure authenticationFailure)
The method declares: bool authenticated = false;
then goes on to authenticate the user.
Whenever authenticated
is set to true or false, authenticationFailure
is set to AuthenticationFailure.Failure
or AuthenticationFailure.Success
correspondingly.
So basically I can use either authenticationFailure or the return value of the method to check the result. However it seems to be a pointless violation of DRY to have these two approaches in the same method.
Just to clarify, authenticationFailure is not used anywhere else in the method so it appears to be totally redundant.
At the moment I'm doing this:
public static bool IsValidLDAPUser(string username, string password, string domain)
{
var authenticationStatus = new AuthenticationFailure();
if (ActiveDirectoryAuthenticationService.TryAuthenticate(username, password, domain, out authenticationStatus))
return true;
else return false;
}
But I could do this and get a similar result:
public static AuthenticationFailure IsValidLDAPUser(string username, string password, string domain)
{
var authenticationStatus = new AuthenticationFailure();
ActiveDirectoryAuthenticationService.TryAuthenticate(username, password, domain, out authenticationStatus)
return authenticationStatus;
}
- Why would you have a reference parameter that does the same thing as the return value?
- Which one should I use to check the result and does it make any difference?
- Is this just a case of bad code or am I missing the point?
Thanks in advance!