Вопрос

I am trying to get UserPro class to read a method from User class but I keep experiencing the "The name 'Password' does not exist in the current context" and "The name 'UserName' does not exist in the current context" on the following code:

public class UserPro : IProvidePrincipal
{

    private User _userRepo;

    public UserPro (User userRepo)
   {
    this._userRepo = userRepo;
   }

    public IPrincipal CreatePrincipal(string username, string password)
    {
        try 
        {
            if (!_userRepo.Validate(UserName, Password))
            {
                return null;
            }

            else
        {
            var identity = new GenericIdentity(username);
            IPrincipal principal = new GenericPrincipal(identity, new[] { "Admin" });

            return principal;
        }
    }
    catch
    {
        return null;
    }
    }   
}

user class:

 public bool Validate(string UserName, string Password)
    {
        var user = db.api_login.FirstOrDefault(u => u.username == UserName
                 && u.password == Password);

        if (user != null)
        {
            if (user.password == Password)
            {
                return true;
            }
        }

        return false;
    }

any advice where I am going wrong in the method? Many thanks

Это было полезно?

Решение

I think the U of Username and P of Password should be small. Example:

if (!_userRepo.Validate(userName, password))
            {
                return null;
            }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top