从代码的重置、转码、用户口令再转述和使用相同的转码密码,再到再从其他业务登录到更高级的密码。但是AD并没有对用户进行身份认证,在AD中,我们从代码中更新userPassword
、holcimIsRegistered
和userAccountControl
属性,以重置相应的密码。
当我们从ADSI手工重置机机AD用户密码时(右击用户->,转到复位密码,再转回转位密码,再复位→,复位密码),那么AD就是用新密码对用户进行认证。userPassword
和unicodePwd
属性都没有更新。
我们尝试从ADSI和代码更新unicodePwd
属性,但是它不允许用户从我们观察到的代码中更新它的值
[LDAP: error code 53 - 0000001F: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM)]
我们比较了ADSI之前和重新设置密码的用户详细信息,发现很少有细节被更新(BadLogonCount:0
、badPasswordTime:0
、badPwdCount:0
、lastLogoff:0
、lastLogon:0
、logonCount:0
、Modified
、modifyTimeStamp
、msDS-User-Account-Control-Computed
、PasswordExpired:false
、PasswordLastSet
、uSNChanged
和whenChanged
)。
当我们试图修改usnChanged
时,ADSI中的msDS-User-Account-Control-Computed
发现这两个属性不能从ADSI中编辑,并且从代码中获得SchemaViolationException
. For passwordExpired
和badLogonCount
属性,我们在从代码和ADSI修改它时面对NoSuchAttributeException
,这两个属性都丢失了。
不然我们怎么能把这事做好?
发布于 2022-02-15 15:03:11
若要重置密码,请更新unicodePwd
属性。文献资料告诉您几个需求:
此页有一个如何用Java实现此操作的示例,我已经在下面粘贴了这个示例。它没有提到加密,但是您可以使用LDAPS (LDAPS),这可以通过使用LDAPS://
而不是仅使用LDAP://
来实现。这假设AD服务器为LDAPS正确设置,并且没有防火墙阻塞LDAPS端口(636)。
/**
* Update User Password in Microsoft Active Directory
* @param username
* @param password
*/
public void updateUserPassword(String username, String password)
{
try
{
System.out.println("updating password...\n");
String quotedPassword = "\"" + password + "\"";
char unicodePwd[] = quotedPassword.toCharArray();
byte pwdArray[] = new byte[unicodePwd.length * 2];
for (int i = 0; i < unicodePwd.length; i++)
{
pwdArray[i * 2 + 1] = (byte) (unicodePwd[i] >>> 8);
pwdArray[i * 2 + 0] = (byte) (unicodePwd[i] & 0xff);
}
System.out.print("encoded password: ");
for (int i = 0; i < pwdArray.length; i++)
{
System.out.print(pwdArray[i] + " ");
}
System.out.println();
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("UnicodePwd", pwdArray));
ldapContext.modifyAttributes("cn=" + username + BASE_NAME, mods);
}
catch (Exception e)
{
System.out.println("update password error: " + e);
}
}
发布于 2022-08-10 18:27:35
或者,您可以使用PowerShell重置AD密码。
此Powershell函数帮助您从域客户端计算机重置活动目录用户密码。域用户必须是域管理的成员,才能从域工作站执行密码管理。在关闭密码时,此函数还解锁用户帐户。
Function Reset-ADUserPassword {
Param ([Parameter(Mandatory = $true, Position = 0,
HelpMessage = 'Enter User Name')]
[ValidateNotNull()]
[string] $Username,
[Parameter(Mandatory = $true, Position = 1,
HelpMessage = 'Enter Password')]
[ValidateNotNull()]
[string] $Password
)
Invoke-Command -ComputerName <ActiveDirectoryServerName> -ArgumentList $Username, $Password -ScriptBlock { param($Username, $Password) import-module activedirectory; Unlock-ADAccount -Identity $Username ; enable-adaccount $Username ; Set-ADAccountPassword $Username -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force); get-aduser -identity $Username -Properties * | select-object UserprincipalName }
Write-Output "Password Set Successfully for the user: $Username and the password is: $Password ";
}
在Powershell上运行上述函数后,使用下面的命令重置密码。
Reset-ADUserPassword -Username abc -Password test@123
https://stackoverflow.com/questions/71128351
复制相似问题