<commit_before>class User

  include DataMapper::Resource
  attr_accessor :password, :confirm_password

  # Filters.
  before :save, :encrypt_password

  # Database fields.
  property :id, Serial

  property :username, String,
    :required => true,
    :length => 5..256,
    :unique => true

  property :email, String,
    :required => true,
    :format => :email_address,
    :unique => true

  property :password_hash, String,
    :required => true,
    :length => 20..256

  property :password_salt, String,
    :required => true,
    :length => 20..256

  property :created_at, DateTime

  # Outside validations.
  validates_presence_of :password, :confirm_password,
    :messages => { :presence => "You have to type a password and confirm it." }

  # Validation methods.
  def self.login user
    begin
      u = User.find(:username, user['username'])
      u.password = user['password']
      hash = BCrypt::Engine.hash_secret u.password, u.password_salt
      u = nil unless hash == u.password_hash
      return u
    rescue
      return nil
    end
  end

  def save
    encrypt_password
    super
  end

  # Helper methods.
  def encrypt_password
    if password != nil && password == <PASSWORD>
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret password, password_salt
    end
  end<commit_msg>Sessions bug fixed.<commit_after>class User

  include DataMapper::Resource
  attr_accessor :password, :<PASSWORD>_password

  # Filters.
  before :save, :encrypt_password

  # Database fields.
  property :id, Serial

  property :username, String,
    :required => true,
    :length => 5..256,
    :unique => true

  property :email, String,
    :required => true,
    :format => :email_address,
    :unique => true

  property :password_hash, String,
    :required => true,
    :length => 20..256

  property :password_salt, String,
    :required => true,
    :length => 20..256

  property :created_at, DateTime

  # Outside validations.
  validates_presence_of :password, :confirm_password,
    :messages => { :presence => "You have to type a password and confirm it." }

  # Validation methods.
  def self.login user
    begin
      u = User.first(:username, user['username'])
      u.password = user['password']
      hash = BCrypt::Engine.hash_secret u.password, u.password_salt
      u = nil unless hash == u.password_hash
      return u
    rescue Exception => e
      puts e
      return nil
    end
  end

  def save
    encrypt_password
    super
  end

  # Helper methods.
  def encrypt_password
    if password != nil && password == <PASSWORD>
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret password, password_salt
    end
  end
{'fraction_non_alphanumeric': 0.10433212996389891, 'fraction_numerical': 0.010108303249097473, 'mean_word_length': 2.975609756097561, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 31, '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': '3657016', 'n_tokens_mistral': 878, 'n_tokens_neox': 820, 'n_words': 237}