Feature #3155 ยป cracklib.diff
app/models/user.rb 2011-11-30 16:45:19 +0000 | ||
---|---|---|
16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 | |
18 | 18 |
require "digest/sha1" |
19 |
require "password" |
|
19 | 20 | |
20 | 21 |
class User < Principal |
21 | 22 | |
... | ... | |
375 | 376 |
protected |
376 | 377 |
|
377 | 378 |
def validate |
378 |
# Password length validation based on setting |
|
379 |
if !password.nil? && password.size < Setting.password_min_length.to_i |
|
380 |
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i) |
|
379 |
if !password.nil? |
|
380 |
if password.size < Setting.password_min_length.to_i |
|
381 |
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i) |
|
382 |
else |
|
383 |
pw = Password.new(password) |
|
384 |
pw.check |
|
385 |
end |
|
381 | 386 |
end |
387 |
rescue Password::WeakPassword => reason |
|
388 |
errors.add(:password, :weak, :reason => reason) |
|
382 | 389 |
end |
383 | 390 |
|
384 | 391 |
private |
config/locales/en.yml 2011-11-30 15:21:41 +0000 | ||
---|---|---|
105 | 105 |
blank: "can't be blank" |
106 | 106 |
too_long: "is too long (maximum is {{count}} characters)" |
107 | 107 |
too_short: "is too short (minimum is {{count}} characters)" |
108 |
weak: "unacceptably weak: {{reason}}" |
|
108 | 109 |
wrong_length: "is the wrong length (should be {{count}} characters)" |
109 | 110 |
taken: "has already been taken" |
110 | 111 |
not_a_number: "is not a number" |