-
Notifications
You must be signed in to change notification settings - Fork 81
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
Use BCrypt to encrypt backup codes #111
base: main
Are you sure you want to change the base?
Conversation
return false unless backup_codes.present? | ||
|
||
valid_code = backup_codes.find do |backup_code| | ||
backup_code = BCrypt::Password.new(backup_code) if self.class.otp_backup_codes_encrypted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [98/80]
self.plain_backup_codes = backup_codes | ||
|
||
backup_codes = backup_codes.map do |code| | ||
cost = ActiveModel::OneTimePassword.min_bcrypt_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [112/80]
|
||
include InstanceMethodsOnActivation | ||
|
||
before_create(**options.slice(:if, :unless)) do | ||
self.otp_regenerate_secret if !otp_column | ||
self.otp_regenerate_counter if otp_counter_based && !otp_counter | ||
otp_regenerate_backup_codes if backup_codes_enabled? | ||
self.otp_regenerate_backup_codes if backup_codes_enabled? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/RedundantSelf: Redundant self detected.
@@ -27,13 +33,14 @@ def has_one_time_password(options = {}) | |||
self.otp_backup_codes_column_name = (options[:backup_codes_column_name] || OTP_DEFAULT_BACKUP_CODES_COLUMN_NAME).to_s | |||
self.otp_backup_codes_count = options[:backup_codes_count] || OTP_DEFAULT_BACKUP_CODES_COUNT | |||
self.otp_one_time_backup_codes = options[:one_time_backup_codes] || OTP_BACKUP_CODES_ENABLED_BY_DEFAULT | |||
self.otp_backup_codes_encrypted = options.fetch(:backup_codes_encrypted, OTP_BACKUP_CODES_ENCRYPTED_BY_DEFAULT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [119/80]
@@ -1,5 +1,6 @@ | |||
require "active_model" | |||
require "active_support/core_ext/module/attribute_accessors" | |||
require "bcrypt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
@@ -7,7 +7,7 @@ class User | |||
define_model_callbacks :create | |||
attr_accessor :otp_secret_key, :otp_backup_codes, :email | |||
|
|||
has_one_time_password one_time_backup_codes: true | |||
has_one_time_password one_time_backup_codes: true, backup_codes_encrypted: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [82/80]
@@ -0,0 +1,11 @@ | |||
class UserWithEncryptedCodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
@gooroodev can you review this PR please? |
Hey @admsev , thanks for summoning me! Summary of Changes
Issues, Bugs, and Typos
General Review of Code Quality and Style
OverallThe pull request introduces a valuable feature by adding encryption for backup codes using BCrypt. The implementation is clean, and the tests ensure that the feature works as expected. The minor issues identified can be easily fixed to improve the robustness of the code. Yours, Gooroo.dev |
No description provided.