2016-07-08 69 views
0

我想要一位主管能夠替代用戶Asp.Net管理員的核心檢查密碼

例如,人未通過檢查並需要主管驗證是否可以繼續。

我目前有一個窗體,從視圖返回用戶名和密碼。我希望能夠以驗證他們是監督員無需登錄他們

控制器:

[HttpPost] 
    [AllowAnonymous] 
    [ValidateAntiForgeryToken] 
    public async Task<IActionResult> verify(verifyViewModel model) 
    {  //this creates the user and their subdomain 
     string str_UserName = model.UserName + "@" + model.Subdomain; 
      var verify = await _userManager.VerifyPasswordAsync(str_UserName, model.Password); 
     if (verify == true){ continue with program } 

型號:

public class verifyViewModel 
{ 
    [Required] 
    public string Subdomain { get; set; } 

    [Required] 
    public string UserName { get; set; } 

    [Required] 
    [DataType(DataType.Password)] 
    public string Password { get; set; } 


} 

_userManager.VerifyPasswordAsync(str_UserName, model.Password); 

我想我我錯過了什麼,但我不知道從哪裏繼續從這裏

回答

0
public async Task<bool> VerifyAdmin(string username, string password) 
    { //GET THE USER WE WANT TO VERIFY.           //model.UserName 
     var userToVerify = await _context.ApplicationUser.SingleOrDefaultAsync(u => u.UserName == username); 
     //IF THE USER IS NOT AN ADMIN, RETURN FALSE. 
     if (!userToVerify.IsAdmin) 
     { 
      return false; 
     } 
     //INITIALIZE RESULT. 
     bool result = false; 
     //CHECK THE USERNAME AND PASSWORD. 
     result = await _userManager.CheckPasswordAsync(userToVerify, password); 
     //RETURN THE RESULT. 
     return result; 
    } 

這是我們最後想出瞭解決方案。隨意建議更改或升級!