Skip to content

Commit

Permalink
add digits to password (#2705)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattroyc authored Mar 29, 2023
1 parent 4d52bc1 commit 36cd382
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def password(min_length: 8, max_length: 16, mix_case: true, special_characters:
password << lower_chars[rand(lower_chars.count - 1)]
character_bag += lower_chars

digits = ('1'..'9').to_a
password << digits[rand(digits.count - 1)]
character_bag += digits

if character_types.include?(:mix_case)
upper_chars = ('A'..'Z').to_a
password << upper_chars[rand(upper_chars.count - 1)]
Expand Down
7 changes: 6 additions & 1 deletion test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def test_username_with_range_and_separators
end

def test_password
assert_match(/\w{3}/, @tester.password)
password = @tester.password

assert_match(/\w{3}/, password)
assert_match(/\d/, password)
assert_match(/[a-z]/, password)
assert_match(/[A-Z]/, password)
end

def test_password_with_integer_arg
Expand Down

0 comments on commit 36cd382

Please sign in to comment.