Changing password in ASP.NET Core

I am struggling to change the login passwords if I don’t know the old password.

My app has an admin feature where the admin created user passwords when he creates an account.

User a custom login form so no one but him can create the account

This is for an internal business. When the user forgets there password they have to go to the admin to reset/change it. I can only do it if i know the current password.

I have tried the UserManager.ChangePasswordAsync but this requires the old password and confirm password which I don’t have or need.

AccountController: this edits the users perfect accept the password

[Authorize(Roles = "Admin")]
[HttpGet]
public async Task<ActionResult> Edit(string id)
{
    ViewData["RoleId"] = new SelectList(_context.Roles, "Id", "Name");
    var user = new UserViewModel();
    var result = await _userManager.FindByIdAsync(id);
    user.FirstName = result.FirstName;
    user.LastName = result.LastName;
    user.Email = result.Email;
    user.Id = result.Id;

    return View(user);
}

[Authorize(Roles = "Admin")]
[HttpPost]
public async Task<ActionResult> Edit(string id, UserViewModel model)
{
    var result = await _userManager.FindByIdAsync(id);
    result.FirstName = model.FirstName;
    result.LastName = model.LastName;   
    result.Email = model.Email;
    result.RoleId = model.RoleId;
    result.Id = model.Id;

    var finalresult = await _userManager.UpdateAsync(result);

    if (finalresult.Succeeded)
    {
        return RedirectToAction("Index");
    }
    else
    {
        return View(model);
    }
}

Edit view:

@model Deadfiles.ViewModels.UserViewModel

@{
    ViewData["Title"] = "Edit User";
}

<h1>Edit User</h1>
<hr />
<div class="row">
    <div class="col-md-12">
        <form asp-action="Edit">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="row">


                <div class="col-md-6">
                    <div class="form-group">
                        <label asp-for="FirstName" class="control-label"></label>
                        <input asp-for="FirstName" class="form-control" />
                        <span asp-validation-for="FirstName" class="text-danger"></span>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label asp-for="LastName" class="control-label"></label>
                        <input asp-for="LastName" class="form-control" />
                        <span asp-validation-for="LastName" class="text-danger"></span>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label asp-for="Email" class="control-label"></label>
                        <input asp-for="Email" class="form-control" />
                        <span asp-validation-for="Email" class="text-danger"></span>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label asp-for="Password" class="control-label"></label>
                        <input asp-for="Password" type="password" class="form-control" />
                        <span asp-validation-for="Password" class="text-danger"></span>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label asp-for="RoleId" class="control-label"></label>
                        <select asp-for="RoleId" class="form-control" asp-items="ViewBag.RoleId"></select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <a asp-action="Index" class="btn btn-danger">Back to List</a>
                <input type="submit" value="Update User" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }
}

I have tried the UserManager.ChangePasswordAsync() but the requires the old password and I only have the new password as an admin

3

You can use the ResetPasswordAsync method available on the UserManager.

An example of how you might use this is as follows:

var user = await _userManager.FindByIdAsync(id);

if (user is null)
{
    // do something relevant to not locating the user
}

var token = await _userManager.GeneratePasswordTokenAsync(user);
var passwordResetResult = await _userManager.ResetPasswordAsync(
    user,
    token,
    model.Password
);

if (!passwordResetResult.Succeeded)
{
    // do something relevant to not successfully resetting the password
}

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật