header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Random Password gen
Last Post 26 Jul 2011 04:35 AM by Milo. 7 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BobdeeUser is Offline
Basic Member
Basic Member
Posts:130
Avatar

--
13 May 2011 01:01 AM
    Hi,

    I create a lot of users, and have been playing with random passwords thru powershell and at the moment I can't seem to write something that will use only alpabetical characters.  Sure, the requirement for a strong password is an obvious security consideration but that will be forced upon the user at first logon - so I wanted to generate an easy to type / read basic 8 char password for each user.

    For example : -

    $randompwd = [System.Web.Security.Membership]::GeneratePassword(8,0)
    $randompwd = $randompwd.ToLower()

    Which works, but the GeneratePassword method will use non-alpabetic characters, and I cannot seem to get around it - even by using 26 -replace commands on the $randompwd variable.  So, I'm a bit stuck.

    Any help will be appreciate, and thanks in advance.

    Robbie.

    JonathanUser is Offline
    Basic Member
    Basic Member
    Posts:109
    Avatar

    --
    13 May 2011 02:42 AM
    Hi Bobdee,

    Jeff Hicks posted an interesting article about generating random strings at the end of April. You can get that information here (http://jdhitsolutions.com/blog/2011...ore-1389). Hope this helps.
    Jonathan Tyler
    http://powershellreflections.wordpress.com
    Follow Me On Twitter
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:352
    Avatar

    --
    13 May 2011 03:50 AM
    This will generate a random password of eight letters (upper and lower case). You can adjust it to only do lowercase and more or less letters:

    $alpha = 65,97 | %{$_..($_+25) | %{[char]$_}} #puts all alpha characters in an array you could do just lower case or just uppercase here.
    (Get-Random $alpha -Count 8) -join '' #feeds the array the get-random cmdlet which grabs 8 elements randomly and joins them together with no spaces.
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:352
    Avatar

    --
    13 May 2011 03:57 AM
    If you wanted something that was a bit more memorable you could do the same thing with a list of word. There are all kinds of dictionaries (word lists) out on the Internet that hackers use for password cracking, or you could make your own and do something like this:

    $words = gc .\wordlist.txt
    (get-random $words -count 2) -join '.'

    The above code would grab two words from your list randomly and join them with a character (in this case a period).

    There all kinds of possibilities here...
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    13 May 2011 05:05 AM

    That's fantastic thanks for the responses guys.  I'll mill over both options.

    I adapted the Jeff Hicks script to suit my needs.  I do like the word import however - good idea!

    Param([string]$source="AbCdEfGhIjKlMnOpQrStUvWxYz",[int]$sourceLength=8)

     $ofs=""

    [string]$sourceString=$source.ToCharArray() | Get-Random -count $sourceLength

    $sourceString

    Thanks again

    Robbie.

    MiloUser is Offline
    New Member
    New Member
    Posts:37
    Avatar

    --
    26 Jul 2011 04:08 AM
    I always use following function to generate an automatic password.
    You can set all specifications in the funtion for the needed password to be created

    Function Create-Password {
    $passwoord = New-Object system.random 
            #How many characters in the password
            [int]$passwordlength = 8
           
            ##Make sure that number of characters below are not greater than $passwordlength!!
           
            #Minimum Upper Case characters in password
            [int]$min_upper = 2
           
            #Minimum Lower Case characters in password
            [int]$min_lower = 2
           
            #Minimum Numerical characters in password
            [int]$min_number = 2
           
                   
            #Misc password characters in password
            [int]$min_misc = ($passwordlength - ($min_upper + $min_lower + $min_number))
           
            #Characters for the password
            $upper = @("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
            $lower = @("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
            $number = @(1,2,3,4,5,6,7,8,9,0)
            #$symbol = @("!","@","#","%","&","(",")","`"",".","<",">","+","=","-","_")
            $combine = $upper + $lower + $number + $symbol
           
            $password = @()
           
            #Start adding upper case into password
            1..$min_upper | % {$password += Get-Random $upper}
            #Add lower case into password            
            1..$min_lower | % {$password += Get-Random $lower}
            #Add numbers into password
            1..$min_number | % {$password += Get-Random $number}
           
            #Add symbols into password
            #1..$min_symbol | % {$password += Get-Random $symbol}    
           
            #Fill out the rest of the password length
            1..$min_misc | % {$password += Get-Random $combine}            
           
            #Randomize password
            Get-Random $password -count $passwordlength | % {[string]$randompassword += $_}
            Return $randompassword 
    }
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    26 Jul 2011 04:10 AM
    @Milo

    Good approach as it easily lends itself to removing "1" and "l", for example. These can be confusing to distinguish some times...
    MiloUser is Offline
    New Member
    New Member
    Posts:37
    Avatar

    --
    26 Jul 2011 04:35 AM
    I found this ellswhere and did a modification , but indeed ...
    I will copy my full Script ... this does an automatic creation of Special & Service accounts :)
    I will open a new topic for that... there is some modification needed I think :)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer