microsoft / microsoft/sqlmanagementobjects
Login.ChangePassword() leaves MustChangePassword and IsLocked stale - the property bag is never updated or invalidated
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 143
- Fork
- 28
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
After a successful Login.ChangePassword(newPassword, unlock: true, mustChange: true), reading login.MustChangePassword on the same object still returns the old value (typically False) until Refresh() is called. The same applies to the other properties the ALTER changes: IsLocked after an unlock, IsPasswordExpired, PasswordLastSetTime, IsMustChange.
This is the same object-cache pattern as #40 (Database.SetOwner() not updating .Owner): a method executes DDL immediately but neither updates nor invalidates the cached properties it just changed on the server.
Repro
$login = $server.Logins["testlogin"] # SQL login, MustChangePassword currently False
$login.ChangePassword("N3wP@ssw0rd!", $true, $true)
$login.MustChangePassword # False - stale; the server says otherwise:
# SELECT LOGINPROPERTY('testlogin', 'IsMustChange') --> 1
$login.Refresh()
$login.MustChangePassword # True
dbatools carries the workaround with the comment "We need to refresh login after ChangePassword. Otherwise, MustChangePassword will appear as False" (New-DbaLogin.ps1#L610-L611), and its Set-DbaLogin re-reads the login after unlocking for the same reason.
Mechanism
All ChangePassword overloads (LoginBase.cs#L142-L282) end in ExecuteLoginPasswordOptions (LoginBase.cs#L533-L555), which builds ALTER LOGIN ... WITH PASSWORD=... [UNLOCK] [MUST_CHANGE] and runs ExecutionManager.ExecuteNonQuery — and returns. Nothing touches the property bag.
A helper that does update the bag exists — SetMustChangePassword (LoginBase.cs#L334-L347) — but it early-returns unless the object is in design mode, and is only called from Create().
Suggested fix
After a successful non-recording execution, invalidate the affected cached properties so the next read fetches current values from the server — the approach proposed for #40 in PR #231. For ChangePassword that covers at least MustChangePassword, IsLocked, IsPasswordExpired, IsMustChange, PasswordLastSetTime, PasswordHash.
Happy to submit a PR along those lines if that helps.
This was created by Claude and reviewed by Andreas Jordan.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong src/Microsoft/SqlServer/Management/Smo/LoginBase.cs, đọc các overload của ChangePassword và ExecuteLoginPasswordOptions, sau đó so sánh hành vi của chúng với SetMustChangePassword. Sau khi thực thi thành công mà không ghi nhận, hãy vô hiệu hóa các thuộc tính đã lưu trong bộ nhớ đệm bị ảnh hưởng để các lần đọc trên cùng một đối tượng phản ánh kết quả của ALTER LOGIN đối với MustChangePassword, IsLocked, IsPasswordExpired, IsMustChange, PasswordLastSetTime và PasswordHash.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- csharp, sql
- Lĩnh vực
- backend-api-design, databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 72/100