Random password

Tagged with security Rails

Language: Ruby

Generate a random password

View as text

    def random_password
      c = %w( b c d f g h j k l m n p qu r s t v w x z ) +
      %w( ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr )
      v = %w( a e i o u y )
      f, r = true, ''
      6.times do
        r << ( f ? c[ rand * c.size ] : v[ rand * v.size ] )
        f = !f
      2.times do
        r << ( rand( 9 ) + 1 ).to_s
Original snippet written by Brian Hogan
Last updated at 07:00 AM on Jan 01, 2010 by Brian Hogan

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.