I keep getting this error message and I don't know why

cv28

Error message is:

'_djv.Authenticator' does not contain a definition for 'authenticate' and no extension method 'authenticate' accepting a first argument of type '_djv.Authenticator' could be found (are you missing a using directive or an assembly reference?) my code is below, I have a console app program and a class called authenticator, both pieces of code are down there.

namespace _Authenticator 
{
    public class Authenticator 
    {
        private Dictionary < string, string > dictionary = new Dictionary < string, string > ();

        public Authenticator() 
        {
            dictionary.Add("username1", "password1");
            dictionary.Add("username2", "password2");
            dictionary.Add("username3", "password3");
            dictionary.Add("username4", "password4");
            dictionary.Add("username5", "password5");
        }

        public bool authenticate(string username, string password) 
        {
            bool authenticated = false;

            if (dictionary.ContainsKey(username) && dictionary[username] == password) 
            {
                authenticated = true;
            }
            else 
            {
                authenticated = false;
            }

            return authenticated;
        }
    }
}

using _Authenticator;

namespace _djv 
{
    class Authenticator 
    {
        static void Main(string[] args) 
        {
            Console.WriteLine("Please enter a username");
            var username = Console.ReadLine();

            Console.WriteLine("Please enter your password");
            var password = Console.ReadLine();

            var auth = new Authenticator();

            if (auth.authenticate(username, password)) 
                Console.WriteLine("Valid username/password combination");
            else 
                Console.WriteLine("Invalid username/password combination");

            Console.WriteLine("Press Enter to end");
            Console.ReadLine();
        }
    }
}
Kapol

There is a clash of class names. Your auth variable refers to the class inside _djv namespace. Specify the full name of the class to be able to use it.

var auth = new _Authenticator.Authenticator();

Alternatively, you can create an alias for the class. I'd recommend this approach here as it makes writing code less tedious.

using Auth = _Authenticator.Authenticator;
(...)
var auth = new Auth();

Actually, I think the best idea would be to rename one of the classes. Everything will get a lot cleaner and clearer.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I keep getting a segmentation fault and I don't know why

From Dev

Don't know why I am getting StopIteration error

From Dev

SMTP Error, I don't know why

From Dev

WHy am I keep getting an error message or build error message?

From Dev

I'm getting the error Unexpected symbol 'void' in Unity after copying a code and I don't know why

From Dev

I don't know why I'm getting this error in full join in MySql

From Dev

I keep getting "signal 1: SIGABRT" in swift 3 and I don't know how to get around it

From Dev

Task_Dispose_NotCompleted error but i don't know why

From Dev

Don't know why I receive `error: forward declaration of <class>`

From Dev

I keep getting subscript out of range don't know how to fix it

From Dev

I'm getting an ArrayIndexOutOfBounds Exception and I don't know why. Can someone shed some light?

From Dev

I don't know why this canvas is null

From Dev

Sound is gone, I don't know why

From Dev

title is indented and i don't know why

From Dev

I'm getting a 404 error, don't know what I'm missing

From Dev

I'm getting a java.lang.NullPointerException: null error and I don't know what is missing

From Dev

I don't know why I can't use asfreq()?

From Dev

This is my client and server side code. I don't know why I am getting error "Connect Failed" after running the client code for second time

From Dev

there is an error message like "error: parse error near line" every time i try to run this code and i don't know what to do?

From Dev

Importing multiple (21) tabs from excel into R: Why do I keep getting this error message "Error: unexpected '}' in " }"?

From Dev

I'm new to PHP and I don't understand why I'm getting this undefined variable error

From Dev

Why do I keep getting this mysql error?

From Dev

why do I keep getting a 503 error?

From Dev

Why do I keep getting this NullReferenceException error?

From Dev

I am getting " ; expected " error i don't know where i miss this sign . who to resolve this issue .code is attached

From Dev

Keep getting undeclared variable error and I don't understand where from

From Dev

I created a compressor but archive is corrupted and I don't know why

From Dev

double multiplication is getting rounded, and i don't know how to fix it

From Dev

I don't understand why I am getting "Segmentation fault (core dumped)" error

Related Related

  1. 1

    I keep getting a segmentation fault and I don't know why

  2. 2

    Don't know why I am getting StopIteration error

  3. 3

    SMTP Error, I don't know why

  4. 4

    WHy am I keep getting an error message or build error message?

  5. 5

    I'm getting the error Unexpected symbol 'void' in Unity after copying a code and I don't know why

  6. 6

    I don't know why I'm getting this error in full join in MySql

  7. 7

    I keep getting "signal 1: SIGABRT" in swift 3 and I don't know how to get around it

  8. 8

    Task_Dispose_NotCompleted error but i don't know why

  9. 9

    Don't know why I receive `error: forward declaration of <class>`

  10. 10

    I keep getting subscript out of range don't know how to fix it

  11. 11

    I'm getting an ArrayIndexOutOfBounds Exception and I don't know why. Can someone shed some light?

  12. 12

    I don't know why this canvas is null

  13. 13

    Sound is gone, I don't know why

  14. 14

    title is indented and i don't know why

  15. 15

    I'm getting a 404 error, don't know what I'm missing

  16. 16

    I'm getting a java.lang.NullPointerException: null error and I don't know what is missing

  17. 17

    I don't know why I can't use asfreq()?

  18. 18

    This is my client and server side code. I don't know why I am getting error "Connect Failed" after running the client code for second time

  19. 19

    there is an error message like "error: parse error near line" every time i try to run this code and i don't know what to do?

  20. 20

    Importing multiple (21) tabs from excel into R: Why do I keep getting this error message "Error: unexpected '}' in " }"?

  21. 21

    I'm new to PHP and I don't understand why I'm getting this undefined variable error

  22. 22

    Why do I keep getting this mysql error?

  23. 23

    why do I keep getting a 503 error?

  24. 24

    Why do I keep getting this NullReferenceException error?

  25. 25

    I am getting " ; expected " error i don't know where i miss this sign . who to resolve this issue .code is attached

  26. 26

    Keep getting undeclared variable error and I don't understand where from

  27. 27

    I created a compressor but archive is corrupted and I don't know why

  28. 28

    double multiplication is getting rounded, and i don't know how to fix it

  29. 29

    I don't understand why I am getting "Segmentation fault (core dumped)" error

HotTag

Archive