mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-11 07:02:36 +01:00
Authenticate users with deprecated SHA-1 passwords
This commit is contained in:
parent
8e23d11054
commit
e5708f5ce7
2 changed files with 23 additions and 2 deletions
|
|
@ -123,8 +123,8 @@ class User < ActiveRecord::Base
|
||||||
return nil if candidate.nil?
|
return nil if candidate.nil?
|
||||||
|
|
||||||
if Tracks::Config.auth_schemes.include?('database')
|
if Tracks::Config.auth_schemes.include?('database')
|
||||||
return candidate if candidate.auth_type == 'database' &&
|
return candidate if candidate.auth_type == 'database' and
|
||||||
BCrypt::Password.new(candidate.crypted_password) == pass
|
candidate.password_matches? pass
|
||||||
end
|
end
|
||||||
|
|
||||||
if Tracks::Config.auth_schemes.include?('ldap')
|
if Tracks::Config.auth_schemes.include?('ldap')
|
||||||
|
|
@ -216,6 +216,14 @@ class User < ActiveRecord::Base
|
||||||
crypted_password =~ /^[a-f0-9]{40}$/i
|
crypted_password =~ /^[a-f0-9]{40}$/i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def password_matches?(pass)
|
||||||
|
if uses_deprecated_password?
|
||||||
|
crypted_password == User.sha1(pass)
|
||||||
|
else
|
||||||
|
BCrypt::Password.new(crypted_password) == pass
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def self.salted(s)
|
def self.salted(s)
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,19 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_nil u.uses_deprecated_password?
|
assert_nil u.uses_deprecated_password?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_authenticate_with_deprecated_password
|
||||||
|
assert_nil User.authenticate('mr_deprecated', 'wrong password')
|
||||||
|
assert_equal users(:user_with_sha1_password),
|
||||||
|
User.authenticate('mr_deprecated', 'foobar')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_password_matches
|
||||||
|
assert_not_nil User.authenticate(@admin_user.login, "abracadabra")
|
||||||
|
assert_nil User.authenticate(@admin_user.login, "incorrect")
|
||||||
|
assert_not_nil User.authenticate(users(:user_with_sha1_password).login, "foobar")
|
||||||
|
assert_nil User.authenticate(users(:user_with_sha1_password).login, "wrong")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def create_user(options = {})
|
def create_user(options = {})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue