<commit_before>class User < ActiveRecord::Base
  validates :name, :presence => true, :uniqueness => true

  belongs_to :role

  attr_accessible :email, :password, :password_confirmation, :remember_me

  devise :database_authenticatable, :recoverable, :rememberable, :registerable, :trackable, :confirmable,
         :lockable

  def valid_password?(password)
    if self.hashed_password.present?
      if encrypt_password(password, self.salt) == self.hashed_password
        self.password = password
        self.hashed_password = nil
        self.save!
        true
      else
        false
      end
    else
      super
    end
  end

  def reset_password!(*args)
    self.hashed_password = nil
    super
  end

  #Application need a user to log in
  def before_destroy
    errors.add(:base, I18n.t("activerecord.errors.models.user.self_delete")) if current_user_id == self.id
    errors.add(:base, I18n.t("activerecord.errors.models.user.delete")) if User.count == 1
    errors.blank?
  end
end
<commit_msg>Correcao de senha de usuario<commit_after>class User < ActiveRecord::Base
  validates :name, :presence => true, :uniqueness => true

  belongs_to :role

  attr_accessible :email, :password, :password_confirmation, :remember_me

  devise :database_authenticatable, :recoverable, :rememberable, :registerable, :trackable, :confirmable,
         :lockable

  def valid_password?(password)
    if self.hashed_password.present?
      if User.encrypt_password(password, self.salt) == self.hashed_password
        self.password = password
        self.hashed_password = nil
        self.save!
        true
      else
        false
      end
    else
      super
    end
  end

  def User.encrypt_password(password, salt)
    Digest::SHA2.hexdigest(password + "wibble" + salt)
  end

  def reset_password!(*args)
    self.hashed_password = nil
    super
  end

  #Application need a user to log in
  def before_destroy
    errors.add(:base, I18n.t("activerecord.errors.models.user.self_delete")) if current_user_id == self.id
    errors.add(:base, I18n.t("activerecord.errors.models.user.delete")) if User.count == 1
    errors.blank?
  end
end

{'fraction_non_alphanumeric': 0.09433962264150944, 'fraction_numerical': 0.004941599281221923, 'mean_word_length': 2.839655172413793, 'pattern_counts': {'":': 0, '<': 5, '<?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': '720991', 'n_tokens_mistral': 776, 'n_tokens_neox': 673, 'n_words': 157}