Search code examples
rubysecuritypassword-generator

Secure Password Generation With Random Chars


I am trying to generate a random password that contains special chars using ruby. I would like to know if there is a standard for generating such passwords. I have considered using a weighted probability distribution and assigning weights such that there is a higher probability of picking special chars from , but I am not sure if this is a widely-accepted standard.


Solution

  • You can use SecureRandom (docs):

    require 'securerandom'
    
    password = SecureRandom.base64(15)
    # => "vkVuWvPUWSMcZf9nn/dO"