<commit_before>module DiabeticToolbox::Concerns::Authenticatable
  extend ActiveSupport::Concern

  included do
    attr_accessor :password, :password_confirmation

    validates :email, presence: { message: I18n.t('activerecord.validations.common.required')},
              length: { maximum: 256, message: I18n.t('activerecord.validations.common.maximum', maximum: 256) },
              format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: I18n.t('activerecord.validations.common.authenticatable.email_format')}
    validates :password, on: :create, presence: { message: I18n.t('activerecord.validations.common.required') },
              length: { in: (8..64), message: I18n.t('activerecord.validations.common.length_range', min: 8, max: 64) },
              confirmation: { message: I18n.t('activerecord.validations.common.authenticatable.password_confirmation') }
    validates :password, on: :update, if: :setting_password?,
              length: { in: (8..64), message: I18n.t('activerecord.validations.common.length_range', min: 8, max: 64) },
              confirmation: { message: I18n.t('activerecord.validations.common.authenticatable.password_confirmation') }

    def password=(password_str)
      @password               = <PASSWORD>
      self.encryption_salt    = BCrypt::Engine.generate_salt 12
      self.encrypted_password = BCrypt::Engine.hash_secret(password_str, encryption_salt)
    end

    def authenticate!(password)
      return true if authenticate password
      raise "Authentication Failure For: #{email}"
    end

    def authenticate(password)
      password.present? && encrypted_password.present? && encrypted_password == BCrypt::Engine.hash_secret(password, encryption_salt)
    end

    private
      def setting_password?
        self.password || self.password_confirmation
      end
  end

end<commit_msg>Fixed password validation on update.<commit_after>module DiabeticToolbox::Concerns::Authenticatable
  extend ActiveSupport::Concern

  included do
    attr_accessor :password, :password_confirmation

    validates :email, presence: { message: I18n.t('activerecord.validations.common.required')},
              length: { maximum: 256, message: I18n.t('activerecord.validations.common.maximum', maximum: 256) },
              format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: I18n.t('activerecord.validations.common.authenticatable.email_format')}
    validates :password, on: :create, presence: { message: I18n.t('activerecord.validations.common.required') },
              length: { in: (8..64), message: I18n.t('activerecord.validations.common.length_range', min: 8, max: 64) },
              confirmation: { message: I18n.t('activerecord.validations.common.authenticatable.password_confirmation') }
    validates :password, on: :update,
              length: { in: (8..64), message: I18n.t('activerecord.validations.common.length_range', min: 8, max: 64) },
              confirmation: { message: I18n.t('activerecord.validations.common.authenticatable.password_confirmation') },
              if: :setting_password?

    def password=(password_str)
      @password               = password_str
      self.encryption_salt    = BCrypt::Engine.generate_salt 12
      self.encrypted_password = <PASSWORD>::Engine.hash_secret(password_str, encryption_salt)
    end

    def authenticate!(password)
      return true if authenticate password
      raise "Authentication Failure For: #{email}"
    end

    def authenticate(password)
      password.present? && encrypted_password.present? && encrypted_password == <PASSWORD>::<PASSWORD>.hash_secret(password, encryption_salt)
    end

    private
      def setting_password?
        self.password.present? || self.password_confirmation.present?
      end
  end

end
{'fraction_non_alphanumeric': 0.1308928101132473, 'fraction_numerical': 0.020542533579141427, 'mean_word_length': 3.6658476658476657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '673380', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1101, 'n_words': 209}