Changeset 451
- Timestamp:
- 08/25/06 03:07:49 (2 years ago)
- Files:
-
- login_engine/trunk/README (modified) (1 diff)
- login_engine/trunk/lib/login_engine.rb (modified) (1 diff)
- login_engine/trunk/lib/login_engine/authenticated_user.rb (modified) (2 diffs)
- login_engine/trunk/test/functional/user_controller_test.rb (modified) (1 diff)
- login_engine/trunk/test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
login_engine/trunk/README
r446 r451 240 240 +password_minimum+:: Set your minimum password length. 241 241 Defaults to 5. 242 +password_expiry+:: Number of days until passwords expire. 243 0 means never expire. 244 Defaults to 0 245 +password_recyclable_after+:: Cannot reuse the last n passwords. 246 Defaults to 0 242 247 243 248 == Overriding controllers and views login_engine/trunk/lib/login_engine.rb
r449 r451 61 61 # 0 means it will not expire 62 62 config :password_expiry, 0 63 64 # password cannot be one of the last n passwords 65 # specify here n 66 # 0 means there is no limit 67 config :password_recyclable_after, 0 63 68 64 69 # controls whether or not email is used login_engine/trunk/lib/login_engine/authenticated_user.rb
r449 r451 27 27 validates_length_of :password, { :maximum => 40, :if => :validate_password? } 28 28 29 validates_each :password, {:if => :validate_password? } do |record, attr, value| 30 if LoginEngine.config(:password_recyclable_after) > 0 && record.passwords[0, LoginEngine.config(:password_recyclable_after)].any?{|p| p.salted_password == AuthenticatedUser.salted_password(p.salt, AuthenticatedUser.hashed(value)) } 31 record.errors.add attr, "You cannot reuse any of the last #{LoginEngine.config(:password_recyclable_after)} passwords" 32 end 33 end 34 29 35 protected 30 36 … … 56 62 u 57 63 end 58 64 59 65 end 60 66 login_engine/trunk/test/functional/user_controller_test.rb
r450 r451 435 435 def test_forgot_password 436 436 LoginEngine::CONFIG[:use_email_notification] = true 437 LoginEngine::CONFIG[:password_recyclable_after] = 0 437 438 438 439 do_forgot_password(false, false, false) login_engine/trunk/test/unit/user_test.rb
r449 r451 148 148 u.passwords.first.save 149 149 assert u.password_expired?, "Password should have expired" 150 151 152 150 end 151 152 def test_should_not_be_able_to_change_password_to_any_of_the_last_n_passwords 153 require 'pp' 154 LoginEngine::CONFIG[:password_recyclable_after] = 4 155 156 u = User.new 157 u.login = 'bob_changer' 158 u.email = 'bob_changer@email.com' 159 u.change_password('password') 160 assert u.save 161 u.reload 162 163 u.change_password('password') 164 assert !u.save, "Password saved even though it was not recyclable yet" 165 166 1.upto(10) do |i| 167 if i < LoginEngine::config(:password_recyclable_after) 168 u.change_password('password') 169 assert !u.save, "Password saved #{i} even though it was not recyclable yet" 170 assert_match /cannot reuse/, u.errors[:password] 171 else 172 u.change_password("password#{i}") 173 assert u.save, "Password not saved" 174 end 175 end 176 177 178 179 end 180 153 181 end
