Changing password asp.net identity

与世无争的帅哥 提交于 2019-12-02 10:43:18

问题


Is there a quick way to verify is user exists and based on existence of user name get user id?

(i.e. the user only has the user name and the adds it to change their password)?

I would think something like this... String userId = User.Identity.GetUserId(userName);

I am looking for a quick way for local users to change their password if need be.


回答1:


User.Identity.GetUserId() will return the id of current logged in user. From UserManager you can get any user from their username like this

var user = UserManager.FindByName("the username here");

then you can change password from UserManager again

UserManager.ChangePassword(user.Id, "OldPassword", "NewPassword");



回答2:


Have it, thanks

        var user = UserManager.FindByName(userName);
        String userId = user.Id;


来源:https://stackoverflow.com/questions/30640110/changing-password-asp-net-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!