<commit_before>class User
  include DataMapper::Resource

  property :id, Serial
  property :name, String, :length => (3..40), :unique => true
  property :email, String, :length => (5..40), :unique => true, :format => :email_address
  property :hashed_password, String
  property :salt, String
  property :created_at, DateTime
  property :permission_level, Integer, :default => 1

  has n, :entries

  attr_accessor :password, :password_confirmation

  validates_uniqueness_of :name
  validates_uniqueness_of :email
  validates_presence_of :password_confirmation, :unless => Proc.new { |t| t.hashed_password }
  validates_presence_of :password, :unless => Proc.new { |t| t.hashed_password }
  validates_confirmation_of :password

  def password=(<PASSWORD>)
    @password = <PASSWORD>
    self.salt = User.random_string(10) if !self.salt
    self.hashed_password = User.encrypt(@password, self.salt)
  end

  def self.authenticate(name, pass)
    current_user = first(:name => name)
    return nil if current_user.nil?
    return current_user if User.encrypt(pass, current_user.salt) == current_user.hashed_password
    nil
  end

  def admin?
    permission_level == 1
  end

  protected
  def self.encrypt(pass, salt)
    Digest::SHA1.hexdigest(pass+salt)
  end<commit_msg>Fixed bug when editing user<commit_after>class User
  include DataMapper::Resource

  property :id, Serial
  property :name, String, :length => (3..40), :unique => true
  property :email, String, :length => (5..40), :unique => true, :format => :email_address
  property :hashed_password, String
  property :salt, String
  property :created_at, DateTime
  property :permission_level, Integer, :default => 1

  has n, :entries

  attr_accessor :password, :password_confirmation

  validates_uniqueness_of :name
  validates_uniqueness_of :email
  validates_length_of :password, :minimum => 4, :if => :password_require?
  validates_presence_of :password_confirmation, :if => :password_require?
  validates_confirmation_of :password

  def password=(pass)
    @password = <PASSWORD>
    self.salt = User.random_string(10) if !self.salt
    self.hashed_password = User.encrypt(@password, self.salt) if !@password.blank?
  end

  def self.authenticate(name, pass)
    current_user = first(:name => name)
    return nil if current_user.nil?
    return current_user if User.encrypt(pass, current_user.salt) == current_user.hashed_password
    nil
  end

  def admin?
    permission_level == 1
  end

  def password_require?
    self.new? || (!self.new? && !self.password.blank?)
  end

  protected

  def self.encrypt(pass, salt)
    Digest::SHA1.hexdigest(pass+salt)
  end
{'fraction_non_alphanumeric': 0.11064797271693823, 'fraction_numerical': 0.008715422508525956, 'mean_word_length': 4.420944558521561, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 25, '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': '5785798', 'n_tokens_mistral': 890, 'n_tokens_neox': 839, 'n_words': 213}