Created
January 8, 2009 12:15
-
-
Save Narnach/44704 to your computer and use it in GitHub Desktop.
Generate a random alphanumeric password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Random alphanumeric password generator | |
| # Takes one parameter, which is the password length | |
| # Forces the minimum length to be 10 or more | |
| # | |
| CHARS = (0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a | |
| class << CHARS | |
| def rand | |
| self[Kernel.rand(size)] | |
| end | |
| end | |
| len = ARGV.first.to_i | |
| len = 10 unless len > 0 | |
| len.times { print CHARS.rand} | |
| puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment