• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Powershell "Weighted" Random Complex Password Generator

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

notarat

Member
Joined
Nov 11, 2010
I routinely make passwords and was looking through some of the pre-existing generators and thought I would do the same thing in Powershell as a learning exercise.

The script allows you to:

1- Create any length password
2 - Weight the password generation towards one of 4 categories (Uppercase, Lowercase, Numbers, or Special Characters)
3 - Copies it to your clipboard

Code:
cls
write-host "This script will generate a weighted, randomized password"
write-host "You may assign a "weight" to one of the 4 types of characters used"
Write-Host "so that your password is more personalized"
Read-Host 'Press Enter to continue…' | Out-Null
$sdt0 = Read-Host 'How many total characters do you want the password to contain? : '
$Sdt1 = Read-Host 'How many lowercase letters do you want? : '
$Sdt2 = Read-Host 'How many upper case letters do you want? : '
$Sdt3 = Read-Host 'How many numbers do you want? : '
$Sdt4 = Read-Host 'How many special characters do you want? : '
$s1=(-join ('gmxeustahfwkzrvndcyb'.ToCharArray() | Get-Random -Count $Sdt1))
$s2=(-join ('HXULRMTNGSEVPWAFCZKBDY'.ToCharArray() | Get-Random -Count $Sdt2))
$s3=(-join ('7950281346'.ToCharArray() | Get-Random -Count $Sdt3))
$s4=(-join ("{|}/>(<&*,!@;+#[]\~.):?%$'".ToCharArray() | Get-Random -Count $Sdt4))
$str=$s1+$s2+$s3+$s4
-join ($str.ToCharArray() | Get-Random -Count $sdt0) | clip
Write-Host "The password has been copied to your clipboard."
 
We hired a blind person so I updated the script to use speech and am going back to my other scripts to add speech to them as well.

Code:
cls
Add-Type -AssemblyName System.Speech 
$synth = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak('this script will generate a random password of user specified length using the NMCI password complexity standard')
$synth.Speak('You may assign a weight to one of the four types of characters used in the password')
$synth.Speak('How many total characters do you want the password to contain?')
$sdt0 = Read-Host ' : '
$synth.Speak('How many lower case characters do you want the password to contain?')
$Sdt1 = Read-Host 'How many lowercase letters do you want? : '
$synth.Speak('How many upper case characters do you want the password to contain?')
$Sdt2 = Read-Host 'How many upper case letters do you want? : '
$synth.Speak('How many numbers do you want the password to contain?')
$Sdt3 = Read-Host 'How many numbers do you want? : '
$synth.Speak('How many special characters do you want the password to contain?')
$Sdt4 = Read-Host 'How many special characters do you want? : '
$s1=(-join ('gmxeustahfwkzrvndcyb'.ToCharArray() | Get-Random -Count $Sdt1))
$s2=(-join ('HXULRMTNGSEVPWAFCZKBDY'.ToCharArray() | Get-Random -Count $Sdt2))
$s3=(-join ('7950281346'.ToCharArray() | Get-Random -Count $Sdt3))
$s4=(-join ("{|}/>(<&*,!@;+#[]\~.):?%$'".ToCharArray() | Get-Random -Count $Sdt4))
$str=$s1+$s2+$s3+$s4
-join ($str.ToCharArray() | Get-Random -Count $sdt0) | clip
$synth.Speak('Your randomly generated password has been copied to the clip board')
Write-Host "Your randomly generated password has been copied to the clip board"
 
Why did you randomize the input to CharArray when you already are using a PRNG to pull characters out?
 
Why did you randomize the input to CharArray when you already are using a PRNG to pull characters out?

I'm paranoid about it being truly random so I randomized the input to be used.

Short of grabbing dice and rolling them for each value used from an ASCII Table, I thought this would be best to ensure it's truly random.
 
You're losing some "randomness" by locking your CharArray into a single instantiation and your dependent on the "randomness" of the built-in PRNG. Do you know what type it is? I usually use a run-time variable to seed the built-in PRNG.
 
Back