Skip to content

Commit fd5875c

Browse files
committed
check credential, corrections
1 parent d7d6562 commit fd5875c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/bin/resetpwd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
ad.set_config(config)
1717
ad.__DEBUG__=1
1818
if u.is_backend_concerned(entity):
19-
ad.ad_exec_script(entity,'resetpassword.template',entity['payload']['uid']+ " '"+ entity['payload']['newPassword']) +"'"
19+
ad.ad_exec_script(entity,'resetpassword.template',"-user " + entity['payload']['uid']+ " -newp " + entity['payload']['newPassword'])
2020
else:
2121
u.returcode(0,"not concerned")

src/ps1_templates/changepassword.template

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@ param (
33
[string]$oldp,
44
[string]$newp
55
)
6+
7+
Function Test-ADAuthentication {
8+
param(
9+
$username,
10+
$password)
11+
12+
(New-Object DirectoryServices.DirectoryEntry "",$username,$password).psbase.name -ne $null
13+
}
14+
15+
$test=Test-ADAuthentication -username $user -password $oldp
16+
if ($test -eq $false){
17+
Write-Host "Invalid password"
18+
exit 1
19+
}
20+
621
try{
722
Set-ADUser -Identity $user -CannotChangePassword $false
8-
Set-ADAccountPassword -Identity $user -OldPassword (ConvertTo-SecureString -AsPlainText $oldp -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $newp -Force)
9-
Set-ADUser -Identity $user -CannotChangePassword $true
23+
Set-ADAccountPassword -Identity $user -NewPassword (ConvertTo-SecureString -AsPlainText $newp -Force) -reset
24+
Set-ADUser -Identity $user -CannotChangePassword $true -PasswordNeverExpires $true
1025
}catch{
1126
Write-Host $_
1227
exit 1

0 commit comments

Comments
 (0)