Skip to content

Commit

Permalink
TRST-2676: added emailPasswordSHA256 and passwordSHA1SHA256
Browse files Browse the repository at this point in the history
  • Loading branch information
aliyadeliveroo committed Nov 27, 2024
1 parent 8084e30 commit f403ca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/ravelin/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

module Ravelin
class Password < RavelinObject
attr_accessor :success, :failure_reason, :password_hashed
attr_accessor :success, :failure_reason, :password_hashed, :emailPasswordSHA256, :passwordSHA1SHA256
attr_required :success

# Alternative interface, because when the attr is called "password_hashed",
# the end user might think they need to hash the password themselves
def password=(passwd)
@password_hashed = Digest::SHA256.hexdigest(passwd)
@passwordSHA1SHA256 = Digest::SHA256.hexdigest(Digest::SHA1.hexdigest(passwd))

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA1) that is insecure for password hashing, since it is not a computationally expensive hash function.
end

def password_hashed=(passwd)
@password_hashed = passwd
end

def emailPassword=(emailPassword)
@emailPasswordSHA256 = Digest::SHA256.hexdigest(emailPassword)
end

def passwordSHA1SHA256=(passwd)
@passwordSHA1SHA256 = Digest::SHA256.hexdigest(Digest::SHA1.hexdigest(passwd))

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA1) that is insecure for password hashing, since it is not a computationally expensive hash function.
end

FAILURE_REASONS = %w(BAD_PASSWORD UNKNOWN_USERNAME AUTHENTICATION_FAILURE INTERNAL_ERROR RATE_LIMIT BANNED_USER)

def validate
Expand Down
7 changes: 6 additions & 1 deletion spec/ravelin/login_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'digest'

describe Ravelin::Login do
subject do
Expand All @@ -10,7 +11,8 @@
authentication_mechanism: {
password: {
password: "lol",
success: true
success: true,
emailPassword: "[email protected]",
}
},
custom: {
Expand All @@ -22,6 +24,9 @@

context 'creates instance with valid params' do
it { expect { subject }.to_not raise_exception }

it { expect(subject.authentication_mechanism.password.emailPasswordSHA256).to eq(Digest::SHA256.hexdigest("[email protected]")) }
it { expect(subject.authentication_mechanism.password.passwordSHA1SHA256).to eq(Digest::SHA256.hexdigest(Digest::SHA1.hexdigest('lol'))) }
end

context 'creates an authentication_mechanism object' do
Expand Down

0 comments on commit f403ca2

Please sign in to comment.