0

我想让UserPro类从User类读取一个方法,但我一直遇到“The name'Password'在当前上下文中不存在”和“名称'UserName'不存在于目前情况下”在下面的代码:验证用户详细信息

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; 
    } 
    } 
} 

用户等级:

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; 
    } 

任何意见,我在哪里的方法去错了吗?非常感谢

回答

2

我认为密码的用户名和密码应该很小。 例如:

if (!_userRepo.Validate(userName, password)) 
      { 
       return null; 
      } 
+0

谢谢。这有帮助。 – user3070072