Password Generator Tool
<# .SYNOPSIS Password Generator Tool .DESCRIPTION This script generates secure passwords based on user-defined criteria including length, and the inclusion of uppercase letters, lowercase letters, numbers, and special characters. .NOTES File Name : PasswordGenerator.ps1 Author : [Your Name] Prerequisite : PowerShell V3 or later Version : 1.0 Date : [Current Date] .EXAMPLE .\PasswordGenerator.ps1 #> function Show-Menu { Clear-Host Write-Host "=== Password Generator Tool ===" -ForegroundColor Cyan Write-Host "1. Generate Password" Write-Host "2. Set Password Options" Write-Host "3. View Current Settings" Write-Host "4. Exit" } function Set-PasswordOptions { $script:passwordLength = Read-Host "Enter password length (default is 12)" if ([string]::IsNullOrWhiteSpace($script:passwordLength)) { $script:passwordLength = 12 } $script:includeUppercase = Read-Host "Include uppercase letters? (Y/N, default is Y)" $script:includeUppercase = ($script:includeUppercase -ne 'N') $script:includeLowercase = Read-Host "Include lowercase letters? (Y/N, default is Y)" $script:includeLowercase = ($script:includeLowercase -ne 'N') $script:includeNumbers = Read-Host "Include numbers? (Y/N, default is Y)" $script:includeNumbers = ($script:includeNumbers -ne 'N') $script:includeSpecialChars = Read-Host "Include special characters? (Y/N, default is Y)" $script:includeSpecialChars = ($script:includeSpecialChars -ne 'N') Write-Host "Password options updated." -ForegroundColor Green } function View-CurrentSettings { Write-Host "`nCurrent Password Generation Settings:" -ForegroundColor Yellow Write-Host "Password Length: $script:passwordLength" Write-Host "Include Uppercase: $($script:includeUppercase ? 'Yes' : 'No')" Write-Host "Include Lowercase: $($script:includeLowercase ? 'Yes' : 'No')" Write-Host "Include Numbers: $($script:includeNumbers ? 'Yes' : 'No')" Write-Host "Include Special Characters: $($script:includeSpecialChars ? 'Yes' : 'No')" Write-Host "" } function Generate-Password { $characterSet = @() if ($script:includeUppercase) { $characterSet += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ToCharArray() } if ($script:includeLowercase) { $characterSet += 'abcdefghijklmnopqrstuvwxyz'.ToCharArray() } if ($script:includeNumbers) { $characterSet += '0123456789'.ToCharArray() } if ($script:includeSpecialChars) { $characterSet += '!@#$%^&*()_+-=[]{}|;:,.<>?'.ToCharArray() } if ($characterSet.Count -eq 0) { Write-Host "Error: No character set selected. Please update your settings." -ForegroundColor Red return } $password = -join (1..$script:passwordLength | ForEach-Object { Get-Random -InputObject $characterSet }) Write-Host "`nGenerated Password:" -ForegroundColor Green Write-Host $password Write-Host "" $saveToFile = Read-Host "Do you want to save this password to a file? (Y/N)" if ($saveToFile -eq 'Y') { $fileName = "GeneratedPassword_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt" $filePath = Join-Path -Path $env:USERPROFILE -ChildPath "Desktop\$fileName" $password | Out-File -FilePath $filePath Write-Host "Password saved to: $filePath" -ForegroundColor Green } } # Initialize default settings $script:passwordLength = 12 $script:includeUppercase = $true $script:includeLowercase = $true $script:includeNumbers = $true $script:includeSpecialChars = $true # Main program loop do { Show-Menu $choice = Read-Host "`nEnter your choice (1-4)" switch ($choice) { "1" { Generate-Password } "2" { Set-PasswordOptions } "3" { View-CurrentSettings } "4" { Write-Host "Exiting program..." -ForegroundColor Yellow; break } default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red } } if ($choice -ne "4") { Read-Host "`nPress Enter to continue..." } } while ($choice -ne "4")
This Password Generator Tool includes:
- A menu-driven interface for easy navigation.
- Functions to:
- Generate passwords based on user-defined criteria
- Set password generation options
- View current password generation settings
- Customizable options for password generation:
- Password length
- Inclusion of uppercase letters
- Inclusion of lowercase letters
- Inclusion of numbers
- Inclusion of special characters
- Option to save generated passwords to a file on the desktop.
- Default settings for quick password generation.
Key features:
- Flexible password generation based on user preferences
- Ability to customize password complexity
- Option to save generated passwords securely
- User-friendly interface for easy operation
- Viewing current settings for transparency
This tool is particularly useful for:
- System administrators needing to generate secure passwords
- Users who want to create strong, customized passwords
- IT professionals managing password policies
- Anyone needing quick access to randomly generated passwords
To use this script effectively:
- Run the script in PowerShell
- Use the menu to navigate between generating passwords, setting options, and viewing current settings
- Customize the password generation criteria as needed
- Generate passwords and optionally save them to files
This script provides a simple yet effective way to generate secure passwords with customizable criteria, helping to enhance security practices in various IT and personal scenarios.
Leave a Reply
Want to join the discussion?Feel free to contribute!