Created
August 9, 2009 07:02
-
-
Save ivanoats/164649 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Ivan Storck | |
# 2010-01-01 (ish) | |
# creates a cPanel and URL request string safe password, copies it to the mac clipboard, and echoes it to STDOUT | |
class MacClipboard | |
class << self | |
def read | |
IO.popen('pbpaste') {|clipboard| clipboard.read} | |
end | |
def write(stuff) | |
IO.popen('pbcopy', 'w+') {|clipboard| clipboard.write(stuff)} | |
end | |
end | |
end | |
def random_password(size = 12) | |
chars = (('a'..'z').to_a + ('0'..'9').to_a + ('A'..'Z').to_a + ("!".."/").to_a - %w(% * ; : ' " \ ? ` < > & + #)) - %w(i o 0 1 l 0) | |
(1..size).collect{|a| chars[rand(chars.size)] }.join | |
end | |
def check_pass(pass) | |
score = 0 | |
score += 1 if pass.chars.any? {|char| char =~ /[a-z]/ } | |
score += 1 if pass.chars.any? {|char| char =~ /[A-Z]/ } | |
score += 1 if pass.chars.any? {|char| char =~ /[0-9]/ } | |
score += 1 if pass.chars.any? {|char| char =~ /[!$()+,-.\/]/} | |
if score > 3 then | |
return true | |
else | |
return false | |
end | |
end # check_pass | |
newpass = 'bad-seed' | |
newpass = random_password until check_pass(newpass) | |
MacClipboard.write(newpass) | |
puts newpass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment