lib/pwm.rb in pwm-1.0.3 vs lib/pwm.rb in pwm-1.1.0
- old
+ new
@@ -23,10 +23,14 @@
# Pwm.password(8)
# # => 'oUX4fmqr'
#
# Returns the generated password as a String.
def self.password(length = 16)
- (0..length - 1).inject('') do |pw, n|
- pw + characters[rand(characters.length)]
+ password = ''
+ until (password.match(/[A-Z]/) && password.match(/[a-z]/) && password.match(/[0-9]/))
+ password = (0..length - 1).inject('') do |pw, n|
+ pw + characters[rand(characters.length)]
+ end
end
+ password
end
end