Jun-30-2024, 03:15 PM
ok this works guys, can you please check and let me know
if request.method == 'POST' and form.validate(): result = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Set-ADAccountPassword -Credential $cred -Identity {form.un.data} -OldPassword (ConvertTo-SecureString -AsPlainText {form.op.data} -Force) -NewPassword (ConvertTo-SecureString -AsPlainText {form.cnp.data} -Force) -Server {form.dom.data}', capture_output=True, text=True, shell=False) if 'The specified network password is not correct' in result.stderr: return 'your old/current password is incorrect, please click back and try again' if 'The password does not meet the length, complexity, or history requirement of the domain' in result.stderr: return 'cant re-use one of your old passwords or cant change password as still less than one day old' if result.returncode == 0: return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data) return render_template('password.html', form=form)