Creating password website GUI

Hi all,

I’ve created a password GUI form for users to change there password, here’s the code

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$unlabel = New-Object System.Windows.Forms.Label
$unlabel.Location = New-Object System.Drawing.Point(10,20)
$unlabel.Size = New-Object System.Drawing.Size(280,20)
$unlabel.Text = ‘Please type in your username below:’

$unbox = New-Object System.Windows.Forms.TextBox
$unbox.Location = New-Object System.Drawing.Point(10,40)
$unbox.Size = New-Object System.Drawing.Size(260,20)

$oplabel = New-Object System.Windows.Forms.Label
$oplabel.Location = New-Object System.Drawing.Point(10,60)
$oplabel.Size = New-Object System.Drawing.Size(280,20)
$oplabel.Text = ‘Please type in your old password below:’

$opbox = New-Object System.Windows.Forms.TextBox
$opbox.Location = New-Object System.Drawing.Point(10,80)
$opbox.Size = New-Object System.Drawing.Size(260,20)

$nplabel = New-Object System.Windows.Forms.Label
$nplabel.Location = New-Object System.Drawing.Point(10,100)
$nplabel.Size = New-Object System.Drawing.Size(280,20)
$nplabel.Text = ‘Please type in your new password below:’

$npbox = New-Object System.Windows.Forms.TextBox
$npbox.Location = New-Object System.Drawing.Point(10,120)
$npbox.Size = New-Object System.Drawing.Size(260,20)

$domlist = New-Object System.Windows.Forms.ComboBox
$domlist.text = “”
@(“corp”,“prod”) | ForEach-Object {[void] $domlist.Items.Add($_)}
$domlist.SelectedIndex = 0
$domlist.Location = New-Object System.Drawing.Point(10,160)
$domlist.Size = New-Object System.Drawing.Size(260,20)

$submit = New-Object System.Windows.Forms.Button
$submit.Location = New-Object System.Drawing.Point(10,200)
$submit.Size = New-Object System.Drawing.Size(260,20)
$submit.Text = “Submit”
$submit.Add_Click({
$un = $unbox.text
$op = $opbox.text
$np = $npbox.text
$dom = $domlist.text
$dom1 = “lon-”+$domlist.text+“-dc01.domain.com”
write-host $un $op $np $dom1
Set-ADAccountPassword -Identity $un -OldPassword (ConvertTo-SecureString -AsPlainText “$op” -Force) -NewPassword (ConvertTo-SecureString -AsPlainText “$np” -Force) -server $dom1
})

$form = New-Object System.Windows.Forms.Form
$form.Text = ‘Self Service Password Portal’
$form.Size = New-Object System.Drawing.Size(500,500)
$form.StartPosition = ‘CenterScreen’

$form.Controls.Add($unlabel)
$form.Controls.Add($unbox)
$form.Controls.Add($oplabel)
$form.Controls.Add($opbox)
$form.Controls.Add($nplabel)
$form.Controls.Add($npbox)
$form.Controls.Add($domlist)
$form.Controls.Add($submit)
$form.Add_Shown({$form.Activate()})
$form.ShowDialog()

But how would I go about creating a website for this so users can go on a website and do it

Thanks,
Rob

I will assume there is no Domain to get this done. I did this a while back and it worked well, however, not sure if it works on Servers beyond 2016. Your mileage may vary :slight_smile:

i was hoping to write html code for it for the user input stuff ie labels/textbox/combobox and when they click submit button it runs/talks to powershell to run the powershell command to change the users password?

Microsoft has already done that for you? Is this for a learning project?

What I did was customize the web page HTML in the solution Microsoft provides to my liking. Maybe that will work for you.

1 Like

hi @tonyd yes and no, i want to create an HTML website that allows people to enter in there name, old password, new password and then to call powershell somehow so it can run the change password command to do it

There’s lots of different ways you might consider tackling that depending on the scope and project requirements. However, IMO this is a tad beyond the scope of this forum. As Tony pointed out there seems to be a resource already out there, though I haven’t used it myself.

You might consider doing all the HTML part to capture input instead of Powershell, and consider using PowerShell runspaces to connect your site to a PS endpoint. I know its possible in C#. This is particularly powerful if you have a constrained endpoint that is locked down. For example, you could run a JEA constrained endpoint that exposes commands to your web front end that you call for resetting your password. You might also consider simply looking at software that make all of this more trivial. For example, PowerShell Universal you can probably do something like this w/ ease as you can basically expose a PS script as an API.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.