Ruby Password Generator

Ruby Password Generator


How to generate a random password (like CPanel) like a Ninja; Yeah, I’m exited creating passwords for all my Internet accounts every week, so I decided to develop a quick script in Ruby to generate a list of passwords easily like CPanel style.


Just copy and paste the next Ruby code in a single file named genpasswd (without extension), make it executable with chmod 755 genpasswd and save it in this folder (in a UNIX filesystem) /usr/local/bin/ (You’ll need root privileges to move the file in that location); you can specify the quantity of passwords to generate and the length of each one.

#!/usr/bin/env ruby
quantity = !ARGV[0].nil? ? ARGV[0].to_i : 1
length = !ARGV[1].nil? ? ARGV[1].to_i : 12
chars = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a + ('[email protected]$%&*_+=-_?/.,:;#').split(//)
quantity.times { |index| puts, '').collect{ chars[ rand(chars.size) ] }.join('') }

Check the availability of the command:

$ ls -lhas $(which passwd)
4.0K -rwxr-xr-x 1 root root 301 Sep 3 22:39 /usr/local/bin/genpasswd

Check Quickpass — A C++/QT Password Manager

Do you have a project idea? Let's make it together!