microsoft / microsoft/sqlmanagementobjects
Login.ChangePassword() leaves MustChangePassword and IsLocked stale - the property bag is never updated or invalidated
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 143
- 派生
- 28
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/Microsoft/SqlServer/Management/Smo/LoginBase.cs 开始,阅读 ChangePassword 的重载和 ExecuteLoginPasswordOptions,然后将它们的行为与 SetMustChangePassword 进行比较。成功执行且不记录后,使受影响的缓存属性失效,以便从同一对象读取时,MustChangePassword、IsLocked、IsPasswordExpired、IsMustChange、PasswordLastSetTime 和 PasswordHash 反映 ALTER LOGIN 的结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, sql
- 领域
- backend-api-design, databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100