Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1028547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:24:20+00:00 2026-05-16T12:24:20+00:00

I am using a method that has the following signature: public static bool TryAuthenticate(string

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:24:20+00:00Added an answer on May 16, 2026 at 12:24 pm

    Often there are more error codes than just success or failure. Perhaps the designer of this method is going to add more enumerations for all the different failure types.

    Sometimes, there is also more than one success type — e.g. HTTP has a lot of return codes in the 200 and 300 block that would all be considered success in some way. So the bool tells you generally if it was successful or not, and the enum gives more exact information.

    There are a lot of ways to do it, and this one is unusual, but not against DRY if they plan to add more codes.

    Another way is to just encapsulate into a Result class that has the enum and a IsSuccess property. You could even provide a conversion to bool to make it easy to use in if statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an image component that has a FromBinary method. Wondering how do I
I'm using managed c++ to implement a method that returns a string. I declare
I am using C# to write a method that returns the following information about
I have a partial that renders a select box using the following method: <%=
I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse
Let's say I have the following method: public static int CountNonNullMembers<T>(this IEnumerable<T> enumerable) {
When we remote a method (that is using generics) the remoting sink cannot seem
I am using java language,I have a method that is supposed to return an
The only reliable method that I a have found for using a script to
I got a program that writes some data to a file using a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.