ok,
Here is a powershell script I wrote awhile back. thought Id post it. its a really random password generator:
$pwdlength = [int]
$pwdlength = Read-Host "please provide desired password length"
$bytes = [byte[]][byte]1
$pwd = [string]""
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
for($i=1;$i -le $pwdlength;$i++)
{
$rng.getbytes($bytes)
$rnd = $bytes[0] -as [int]
$int = ($rnd % 74) + 48
$chr = $int -as [char]
$pwd = $pwd + $chr
}
write $pwd
$pwdlength = Read-Host "please provide desired password length"
$bytes = [byte[]][byte]1
$pwd = [string]""
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
for($i=1;$i -le $pwdlength;$i++)
{
$rng.getbytes($bytes)
$rnd = $bytes[0] -as [int]
$int = ($rnd % 74) + 48
$chr = $int -as [char]
$pwd = $pwd + $chr
}
write $pwd
enjoy.
maybe later, I will modify it to control special characters. or if someone wants to figure it out, I will repost the code.
-Nex6
3 comments:
Neat! I like this script.
Hi,
I found this valuable for a problem I had, but I needed it to work as a function and I wanted alphanumeric characters. I did the function conversion and a friend did the alphanumeric part.
Here's the revised version.
function pwdgen ($pwd=$null) {
$pwdlength = [int]128
$bytes = [byte[]][byte]1
$pwd = [string]""
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
for($i=1;$i -le $pwdlength;$i++) {
do {
$rng.getbytes($bytes)
$rnd = $bytes[0] -as [int]
$int = ($rnd % 74) + 48
}
until (($int -ge 48 -and $int -le 57) -or ($int -ge 65 -and $int -le 90))
$chr = $int -as [char]
$pwd = $pwd + $chr
}
write-host $pwd
}
pwdgen
Thanks to the author of the post and the comment above. I ran it this morning as part of a quick password generator for non-essential purposes & I noticed the passwords were in all caps. Was hoping for a bit of variety.
Still - great code!
I ran across this - seems to fit the bill nicely for the time being:
http://gallery.technet.microsoft.com/scriptcenter/c3c5aa2b-12b5-406b-8960-0862248a2e44
Post a Comment