generating random password without special characters

Welcome Forums General PowerShell Q&A generating random password without special characters

Viewing 3 reply threads
  • Author
    Posts
    • #237643
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant

      Hi All
      I am using below code to generate random password .

      $pwd = [System.Web.Security.Membership]::GeneratePassword(15,2)
      random password generated from above function is b}0-ad.GqCz:e>!
      how can i avoid generating special characters like “{” , “}” , please suggest.
    • #237652
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant
      i used below function and it worked thanks
      Function New-SecurePassword {
          $Password = "[email protected]#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray()
          ($Password | Get-Random -Count 8) -Join ''
          }
    • #237658
      Participant
      Topics: 6
      Replies: 104
      Points: 486
      Helping Hand
      Rank: Contributor

      I think all you can do is delete or replace those characters after generating the password. The GeneratePassword method only accepts 2 arguments, length and number of non alpha numeric characters.

      This link might help:

      https://stackoverflow.com/questions/30215047/how-to-remove-curly-braces-from-string-in-powershell

       

    • #237673
      Participant
      Topics: 3
      Replies: 417
      Points: 1,462
      Helping Hand
      Rank: Community Hero

      There are many homegrown password generators. You could take this fine example and just remove the characters/charactersets you don’t want.

      https://gist.github.com/Jaykul/5cb0410abd40672707faf67549404ea8

Viewing 3 reply threads
  • You must be logged in to reply to this topic.