<commit_before>package pl.softwaremill.bootstrap.dao

import pl.softwaremill.bootstrap.domain.User
import pl.softwaremill.bootstrap.common.Utils

class UserDAO {

  // simulates single table in database
  private var list = List(
    User(1, "Admin", "<EMAIL>", Utils.sha256("admin", "Admin"))
  )

  var id: Int = 10

  private def nextId(): Int = {
    id = id + 1
    id
  }

  def loadAll = {
    list
  }

  def count(): Long = {
    list.size
  }

  def add(user: User) {
    val exists: Boolean = list.exists((u: User) => u.email.equalsIgnoreCase(user.email) || u.login.equalsIgnoreCase(user.login))
    if (exists) {
      throw new Exception("User with given e-mail or login already exists")
    }

    list = new User(nextId(), user.login, user.email, user.password) +: list
  }

  def remove(userId: Int) {
    val userOpt: Option[User] = list.find(_.id == userId)

    userOpt match {
      case Some(user) => list = list diff List(user)
      case _ => {}
    }
  }

  def load(userId: Int): Option[User] = {
    list.find(_.id == userId)
  }

  def findBy(p: User => Boolean) = {
    list.find(p)
  }

}<commit_msg>Uses sha256 to encrypt password<commit_after>package pl.softwaremill.bootstrap.dao

import pl.softwaremill.bootstrap.domain.User
import pl.softwaremill.bootstrap.common.Utils

class UserDAO {

  // simulates single table in database
  private var list = List(
    User(1, "Admin", "<EMAIL>", Utils.sha256("admin", "Admin"))
  )

  var id: Int = 10

  private def nextId(): Int = {
    id = id + 1
    id
  }

  def loadAll = {
    list
  }

  def count(): Long = {
    list.size
  }

  def add(user: User) {
    val exists: Boolean = list.exists((u: User) => u.email.equalsIgnoreCase(user.email) || u.login.equalsIgnoreCase(user.login))
    if (exists) {
      throw new Exception("User with given e-mail or login already exists")
    }

    list = new User(nextId(), user.login, user.email, Utils.sha256(user.password, user.login)) +: list
  }

  def remove(userId: Int) {
    val userOpt: Option[User] = list.find(_.id == userId)

    userOpt match {
      case Some(user) => list = list diff List(user)
      case _ => {}
    }
  }

  def load(userId: Int): Option[User] = {
    list.find(_.id == userId)
  }

  def findBy(p: User => Boolean) = {
    list.find(p)
  }

}
{'fraction_non_alphanumeric': 0.14378801042571676, 'fraction_numerical': 0.008688097306689836, 'mean_word_length': 2.8255813953488373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2655091', 'n_tokens_mistral': 820, 'n_tokens_neox': 785, 'n_words': 201}