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

Change password validation to allow longer passwords #923

Merged
merged 1 commit into from
Feb 16, 2022
Merged
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
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def ordergroup
validates_presence_of :first_name # for simple_form validations
validates_length_of :first_name, :in => 2..50
validates_confirmation_of :password
validates_length_of :password, :in => 5..25, :allow_blank => true
validates_length_of :password, :in => 12..50, :allow_blank => true
# allow nick to be nil depending on foodcoop config
# TODO Rails 4 may have a more beautiful way
# http://stackoverflow.com/questions/19845910/conditional-allow-nil-part-of-validation
Expand Down Expand Up @@ -132,7 +132,7 @@ def has_password(password)
end

# Returns a random password.
def new_random_password(size = 3)
def new_random_password(size = 6)
c = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
v = %w(a e i o u y)
f, r = true, ''
Expand Down
18 changes: 9 additions & 9 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@
end

describe do
let(:user) { create :user, password: 'blahblah' }
let(:user) { create :user, password: 'blahblahblah' }

it 'can authenticate with correct password' do
expect(User.authenticate(user.nick, 'blahblah')).to be_truthy
expect(User.authenticate(user.nick, 'blahblahblah')).to be_truthy
end
it 'can not authenticate with incorrect password' do
expect(User.authenticate(user.nick, 'foobar')).to be_nil
end
it 'can not authenticate with nil nick' do
expect(User.authenticate(nil, 'blahblah')).to be_nil
expect(User.authenticate(nil, 'blahblahblah')).to be_nil
end
it 'can not authenticate with nil password' do
expect(User.authenticate(user.nick, nil)).to be_nil
end
it 'can not set a password without matching confirmation' do
user.password = 'abcdefghij'
user.password_confirmation = 'foobarxyz'
user.password = 'abcdefghijkl'
user.password_confirmation = 'foobaruvwxyz'
expect(user).to be_invalid
end
it 'can set a password with matching confirmation' do
user.password = 'abcdefghij'
user.password_confirmation = 'abcdefghij'
user.password = 'abcdefghijkl'
user.password_confirmation = 'abcdefghijkl'
expect(user).to be_valid
end

Expand All @@ -56,13 +56,13 @@
end

it 'can authenticate using email address' do
expect(User.authenticate(user.email, 'blahblah')).to be_truthy
expect(User.authenticate(user.email, 'blahblahblah')).to be_truthy
end

it 'can authenticate when there is no nick' do
user.nick = nil
expect(user).to be_valid
expect(User.authenticate(user.email, 'blahblah')).to be_truthy
expect(User.authenticate(user.email, 'blahblahblah')).to be_truthy
end
end

Expand Down