在ASP.NET Core 2.x中更改密码

时间:2018-08-02 07:08:18

标签: c# asp.net-core-2.0 asp.net-core-identity

如何在Asp core 2.x中由管理员更改用户密码?

或使用短信代码更改密码

我的示例代码:

if (!ModelState.IsValid)
    return View(model);

var user = await _userManager.FindByNameAsync(model.UserName);
if (user == null)
    return RedirectToAction("Index");

if (model.smsCode == user.SmsCode)
{
    user.PasswordHash = model.NewPassword;

    IdentityResult result = await _userManager.UpdateAsync(user);
    if (result.Succeeded)
    {
    }
}

错误:将散列密码保存在数据库中

1 个答案:

答案 0 :(得分:3)

我们不应使用纯文本更新 user.PasswordHash ,而应使用Hash。

 #include <stdio.h>
 #include <unistd.h>

int main(int argc, char** argv)
{
    uid_t uid; //Declare it right here?
    if (argc < 2)
    {
        showUsage(argv[0]);
        return 0;
    }
    //Or should I declare uid_t variable here
    uid = getuid();
    if (uid > 0)
    {
        printf("\nroot privileges required!\n");
        return 0;
    }
  return 0;
}