Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add numbers in #internet::password method #2736

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ def password(min_length: 8, max_length: 16, mix_case: true, special_characters:
password = []
character_bag = []

# use lower_chars by default and add upper_chars if mix_case
# use lower_chars and numbers by default and add upper_chars if mix_case
lower_chars = ('a'..'z').to_a
numbers = (0..9).to_a
password << lower_chars[rand(lower_chars.count - 1)]
character_bag += lower_chars
password << numbers[rand(numbers.count - 1)]
character_bag += lower_chars+numbers

if character_types.include?(:mix_case)
upper_chars = ('A'..'Z').to_a
Expand Down
5 changes: 5 additions & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def test_password_could_achieve_max_length
assert passwords.select { |item| item.length == 16 }.size >= 1
end

def test_password_contains_numbers
password = @tester.password
assert_match(/\d+/, password)
end

def test_password_with_mixed_case
password = @tester.password
upcase_count = 0
Expand Down