PassGen - Password Generator

Pavan G SPavan G S
4 min read

PassGen is a password generator application that helps generate encrypted passwords with combinations of letters, numbers and symbols instantly. The IT Engineers have an option to include the type of parameters that are present in the password.


Steps to generate a password

  1. Select the required parameters for the generation of the password.
  • Length - Choose the number of characters of a password. The IT Engineers can specify any value for the length field.

    1. Count - Multiple passwords can be generated at the same time which helps in saving time.

    2. Different types/combinations of characters can also be chosen as an option.

  1. Once the parameters are set, click on the Generate button. A password will be generated which can be utilized by the user for the required purpose.


Advantages

  • The application has a user-friendly interface and is easy to use.

  • This particular generator does not store the passwords as a log in the backend hence providing stronger security for the users.

  • A lot of time is saved with this instant password generator.


Source Code for the above GUI

[CmdletBinding()]
Param()


Begin {    
    Add-Type -AssemblyName PresentationFramework
    $NewPassScript = {
        [CmdletBinding(DefaultParameterSetName = "All")]

        Param(
            [Parameter(ParameterSetName = "Select")]
            [Switch]$UpperCase,
            [Parameter(ParameterSetName = "Select")]
            [Switch]$LowerCase,
            [Parameter(ParameterSetName = "Select")]
            [Switch]$Digits,
            [Parameter(ParameterSetName = "Select")]
            [Switch]$Symbols,
            [Parameter(ParameterSetName = "Select")]
            [Switch]$linuxSafe,
            [Parameter(ParameterSetName = "All")]
            [Switch]$All,
            [int] $Length = 7, 
            [int] $Count = 1
        )

        Begin {
            $Passwords = @()
            $CharArray = @()

            # Building Char Arrays (ASCII Decimal to Char) 
            $UpperCaseCharArray = (65..90) | ForEach-Object { [char]$_ }
            $LowerCaseCharArray = (97..122) | ForEach-Object { [char]$_ }
            $DigitsCharArray = (48..57) | ForEach-Object { [char]$_ }
            $(33..47), $(58..64), $(91..96), $(123..126) | ForEach-Object { $SymbolsASCII += $_ }
            $SymbolsCharArray = $SymbolsASCII | ForEach-Object { [char]$_ }
            $linuxSafeSymbolsCharArray = $SymbolsCharArray | ForEach-Object { if ($_ -in @("!", "\")) {}else { $_ } }
            # User Selection
            if ($PsCmdlet.ParameterSetName -eq "Select") {
                if ($UpperCase) { $CharArray += $UpperCaseCharArray }
                if ($LowerCase) { $CharArray += $LowerCaseCharArray }
                if ($Digits   ) { $CharArray += $DigitsCharArray }
                if ($Symbols -and !($linuxSafe)) { $CharArray += $SymbolsCharArray }
                if ($linuxSafe -and $Symbols) { $CharArray += $linuxSafeSymbolsCharArray }
            }
            # All Printable ASCII Charaters
            else { 
                $CharArray = (33..126) | ForEach-Object { [char]$_ }
            }
        }

        Process {
            For ($i = 0 ; $i -lt $Count; $i++) {
                $Password = Get-Random -Count $Length -InputObject $CharArray
                $Passwords += (-join $Password)
            }
        }

        End { 
            $Passwords 
        }
    }
    # XAML Definition
    [xml]$MainForm = @"
    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            Title="PassGen" Height="300" Width="290" Background="White" Foreground="Black" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
        <Grid>
            <GroupBox Name="ParametersBox" Header="Parameters" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5,0,5,0">
                <StackPanel Orientation="Vertical" Height="52" VerticalAlignment="Top" Margin="10,5,10,5">
                    <StackPanel Orientation="Horizontal" Height="26" Margin="0,0,0,0" HorizontalAlignment="Center">
                        <Label Name="lbl_length" Content="Length" Width="50" Padding="0,5" HorizontalContentAlignment="Left" ToolTip="Password Length"/>
                        <TextBox Name="Length" Width="55" Height="26" Text="8" TextWrapping="NoWrap" VerticalContentAlignment="Center" ToolTip="Password Length"/>
                        <Label Name="lbl_count" Content="Count" Padding="10,5"  Width="55" Height="26" HorizontalContentAlignment="Right" ToolTip="Number of different passwords to generate"/>
                        <TextBox Name="Count" Width="55" Height="26" Text="1" TextWrapping="NoWrap" VerticalContentAlignment="Center" ToolTip="Number of different passwords to generate"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Height="15" Margin="0,10,0,0" HorizontalAlignment="Center">
                        <CheckBox Name="UpperCase" Content="A-Z" VerticalAlignment="Top" Height="15" Width="56" IsChecked="True" />
                        <CheckBox Name="LowerCase" Content="a-z" VerticalAlignment="Top" Height="15" Width="56" IsChecked="True"/>
                        <CheckBox Name="Digits" Content="0-9"  VerticalAlignment="Top" Height="15"  Width="56" IsChecked="True"/>
                        <CheckBox Name="Symbols" Content="!#@$" VerticalAlignment="Top" Height="15" Width="50"  IsChecked="True"/>

                    </StackPanel>
                </StackPanel>
            </GroupBox>
            <Button Name="Generate" Content="Generate" Margin="10,90
                    ,10,0" VerticalAlignment="Top" Height="20"/>
            <TextBox Name="Result" Margin="10,115,10,10" Padding="5,2" Background="#FF363636" Foreground="White"  ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" IsReadOnly="True"/>
        </Grid>
    </Window>
"@

    # Create Main Window
    $XmlNodeReader = New-Object System.Xml.XmlNodeReader $MainForm
    $MainWindow = [System.Windows.Markup.XamlReader]::Load($XmlNodeReader)



    #Find all elements
    $Generate = $MainWindow.FindName("Generate")
    $Result = $MainWindow.FindName("Result")
    $Length = $MainWindow.FindName("Length")
    $Count = $MainWindow.FindName("Count")
    $UpperCase = $MainWindow.FindName("UpperCase")
    $LowerCase = $MainWindow.FindName("LowerCase")
    $Digits = $MainWindow.FindName("Digits")
    $Symbols = $MainWindow.FindName("Symbols")

    #Add OnClick Click Event to the "Generate" Button
    $Generate.Add_Click( {
            $Result.Text = ""
            $Params = @{
                Length    = $Length.Text 
                Count     = $Count.Text 
                UpperCase = $UpperCase.IsChecked
                LowerCase = $LowerCase.IsChecked
                Digits    = $Digits.IsChecked
                Symbols   = $Symbols.IsChecked
            }
            $Passwords = & $NewPassScript @Params
            foreach ($Password in $Passwords) {
                $Result.Text += $Password + [System.Environment]::NewLine
                Set-Clipboard -value "$passwords"
            }
        })
}

Process { $MainWindow.ShowDialog() | Out-Null }

End {}

<#
_________                                ________    _________
\______   \_____ ___  _______    ____    /  _____/   /   _____/
 |     ___/\__  \\  \/ /\__  \  /    \  /   \  ___   \_____  \ 
 |    |     / __ \\   /  / __ \|   |  \ \    \_\  \  /        \
 |____|    (____  /\_/  (____  /___|  /  \______  / /_______  /
                \/           \/     \/          \/          \/ 
#>

Compile the script to exe for ease of distribution. Kindly check my previous post for the tutorial on how to compile the PowerShell script to exe.

0
Subscribe to my newsletter

Read articles from Pavan G S directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pavan G S
Pavan G S

IT expert mastering PowerShell automation, solution architecture & emerging tech. Crafting efficient solutions for seamless operations. Let's innovate together!