Menu

Password dialogue box

2026-08-23
6 days ago
  • Paul Weston

    Paul Weston - 2026-08-23

    I'm trying to make VC as user-friendly as possible for encrypted volumes (not drives/system), for users who are the lowest end of the tech-savvy spectrum.

    I'm happy to take the user's p/w at the time they create the volume and pass it through the command line just that once.

    I'm less keen to do that every time they want to open it again later, but I also don't want them being confused by KDF, PIM and whatnot. Or clicking on them!

    Is there a way to get VC just to ask for the password, and not give the user any of the other options?

     
  • Gary Marks

    Gary Marks - 7 days ago

    I'm not aware of any means to coerce the VeraCrypt GUI into limiting the options that unfamiliar users sometimes find daunting. An alternative would be to create a script that automatically includes all of the desired mounting options except the password, collecting the password instead via a single item dialog to the user, and then passing all of these items to VeraCrypt in a command line. That avoids including the cleartext password in the script, and you won't have to instruct users in VeraCrypt usage. If you are familiar with PowerShell scripting, I wrote a password dialog function that might fill the bill if you're interested.

     
    • Paul Weston

      Paul Weston - 6 days ago

      Hi Gary, thank you, that's exactly what I'm looking for.

      Happy with PowerShell scripting, please let me have your function, that would be great!

       
  • Gary Marks

    Gary Marks - 6 days ago

    Hi Paul,
    I wrote this as an example when I was auditioning scripting languages to replace the soon-to-be deprecated VBScript. PowerShell won out. Anyway, just copy the entire block of code and paste it into a text file with the .ps1 extension. Run it to make sure this dialog is acceptable, and then add your own code at the end to execute VeraCrypt from the command line using the $Password variable along with your other chosen options (quick link).

    Function GetPassword {
      $Form = New-Object System.Windows.Forms.Form
      $Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
      $Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
      $Form.MaximizeBox = $False
      $Form.MinimizeBox = $False
      $Form.BackColor = "LightGray"
      $Form.Font = New-Object System.Drawing.Font("Arial", 12)
      $Form.Text = "And the password is..."
      $Form.Width = 480
      $Form.Height = 110
    
      $TextBox = New-Object System.Windows.Forms.TextBox
      $TextBox.Left = 10
      $TextBox.Top = 20
      $TextBox.Width = 280
      $TextBox.PasswordChar = '?'
      $TextBox.Add_KeyDown({
        Param($sender, $e)
        If ($e.KeyCode -eq [System.Windows.Forms.Keys]::Enter) {
          $e.Handled = $True   #prevents any unwanted further handling of the event
          $e.SuppressKeyPress = $true   #prevents newline character being added to input string
          New-Variable -Name PasswordText -Value ($TextBox.Text) -Scope Script
          $Form.Dispose()
        }
      })
      $Form.Controls.Add($TextBox)
    
      $ButtonTop = 20
      $ButtonWidth = 70
      $ButtonHeight = 28
      $Button = New-Object System.Collections.ArrayList
      For ($X = 0; $X -lt 2; $X++) {
        $TempButton = New-Object System.Windows.Forms.Button
        $Button.Add($TempButton)
        $Button[$X].Location = New-Object System.Drawing.Point((304+(($ButtonWidth+10)*$X)), $ButtonTop)
        $Button[$X].Width = $ButtonWidth
        $Button[$X].Height = $ButtonHeight   #???
        $Button[$X].BackColor = "White"
        $Button[$X].Add_Click({
          Param($sender)
          If (($sender.Text -eq 'Show')) {
            $sender.Text = 'Mask'
            $TextBox.PasswordChar = 0
          } ElseIf (($sender.Text -eq 'Mask')) {
            $sender.Text = 'Show'
            $TextBox.PasswordChar = '?'
          } ElseIf (($sender.Text -eq "Copy")) {
            Set-Clipboard -Value $TextBox.Text
          }
          $TextBox.Focus()
        })
        $Form.Controls.Add($Button[$X])
      }
      $Button[0].Text = "Show"
      $Button[1].Text = "Copy"
    
      $Form.ShowDialog()
      $RetVal = $PasswordText
      Remove-Variable -Name PasswordText -Scope Script
      Return $RetVal
    }#End_GetPassword
    
    $PW = GetPassword
    $Password = $PW[$PW.Count - 1]  #This trick filters out excess garbage returned from pipeline
    
    #This merely verifies correct assignment of text to the $Password variable
    Add-Type -AssemblyName "PresentationFramework"
    [System.Windows.MessageBox]::Show("String value entered was `"$Password`"")
    
    #So now you have the variable $Password to use in your command line invocation of VeraCrypt from a PowerShell script!
    #Add your own code below this line.
    
     
    • Paul Weston

      Paul Weston - 6 days ago

      Fantastic, thank you! That's going to be very helpful :-)

       
      • Gary Marks

        Gary Marks - 6 days ago

        Happy to be of service!

         

Log in to post a comment.