Fixing the Credentials system. (#3390)

* Checks if password exists for the user, if it doesn't the user is prompted to create one.

It checks if the password is equal to $null using `ValidateCredentials` and if it isn't the variable will be created. If it is equal to $null, a window with text, a textbox and a button will appear asking the user to create a password. That password is then set for the user and the winget installation continues.

* Made this a little more secure

Securing the password variable when it gets created and deleting it after it's done being used.

* Forces the user to input their password and automatically puts their username into the credentials box

* Removed the second greater than 0 check
This commit is contained in:
UnaTried
2025-08-01 17:13:33 +02:00
committed by GitHub
parent cae497b2fe
commit cdd43f5e36
2 changed files with 49 additions and 8 deletions

View File

@ -97,9 +97,9 @@ Function Install-WinUtilProgramWinget {
return $true
}
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $($Program) installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
if ($userChoice -eq 'Yes') {
$getcreds = Get-Credential
$userAcknowledgment = [System.Windows.MessageBox]::Show("You need to input your password to install $($Program) with specific user credentials.", "User credential Prompt", [System.Windows.MessageBoxButton]::Ok)
if ($userAcknowledgment -eq 'Ok') {
$getcreds = Get-Credential $env:USERNAME
$status = Invoke-Winget -wingetId $Program -credential $getcreds
if ($status -eq 0) {
Write-Host "$($Program) installed successfully with User prompt."

View File

@ -4,10 +4,8 @@ function Invoke-WPFInstall {
[PSObject[]]$PackagesToInstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ })
)
<#
.SYNOPSIS
Installs the selected programs using winget, if one or more of the selected programs are already installed on the system, winget will try and perform an upgrade if there's a newer version to install.
#>
if($sync.ProcessRunning) {
@ -34,12 +32,55 @@ function Invoke-WPFInstall {
try {
$sync.ProcessRunning = $true
Show-WPFInstallAppBusy -text "Installing apps..."
if($packagesWinget.Count -gt 0 -and $packagesWinget -ne "0") {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
Add-Type -assembly System.Windows.Forms
$PrincipalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('Machine')
$user = $env:USERNAME
if($packagesWinget.Count -gt 0) {
Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object {
try {
$myPasswordIsBlank = $PrincipalContext.ValidateCredentials($user, $null)
} catch {
$form = New-Object System.Windows.Forms.Form
$form.Text = "Set password for $user"
$form.Size = New-Object System.Drawing.Size(500, 200)
$label = New-Object System.Windows.Forms.Label
$label.Text = 'Maybe a program needs to be installed in "usermode" and you have no password set, you need to set it here. After putting a password into the text box a page asking for your password might open (not right after). If you keep the text box empty, nothing will happen.
REMEMBER THE PASSWORD FOR THE FUTURE. YOU WILL NEED FOR STUFF AND TO LOGIN IF AUTOLOGIN ISN`T SET'
$label.Size = New-Object System.Drawing.Size(480, 60)
$label.Location = New-Object System.Drawing.Point(10, 10)
$form.Controls.Add($label)
$passwordBox = New-Object System.Windows.Forms.TextBox
$passwordBox.Size = New-Object System.Drawing.Size(380, 20)
$passwordBox.UseSystemPasswordChar = $true
$passwordBox.Location = New-Object System.Drawing.Point(10, 125)
$form.Controls.Add($passwordBox)
$button = New-Object System.Windows.Forms.Button
$button.Text = 'Submit'
$button.Size = New-Object System.Drawing.Size(75, 23)
$button.Location = New-Object System.Drawing.Point(400, 125)
$button.Add_Click({
$password = $passwordBox.Text | ConvertTo-SecureString -AsPlainText -Force
if ($password) {
Set-LocalUser -Name $user -Password $password
$password.Close()
$Form.Close()
} else {
[System.Windows.Forms.MessageBox]::Show('No password entered!')
}
})
$form.Controls.Add($button)
$form.ShowDialog() | Out-Null
}
}
Show-WPFInstallAppBusy -text "Installing apps..."
Install-WinUtilWinget
Install-WinUtilProgramWinget -Action Install -Programs $packagesWinget
}
if($packagesChoco.Count -gt 0) {
Install-WinUtilChoco