<commit_before><?php
require(NICHT_PATH_LIB.'StupidPass.class.php');
require(NICHT_PATH_ROOT.'MysqliNichtAuthPbkdf2.class.php');

if(submitted_new_user_form())
  $tpl->assign('messages', handle_form_submission());

$tpl->assign('title', 'Administration');

  function submitted_new_user_form(){
    return isset($_POST['username']) && isset($_POST['password']);
  }

  function handle_form_submission(){
    $messages = array();
    if(!password_confirmation_matches())
      $messages[] = 'Passwords does not match.';
    else
      $messages = create_new_user();

    return $messages;
  }
    
    function password_confirmation_matches(){
      return $_POST['password'] == $_POST['password_confirmation'];
    }

    function create_new_user(){
      $u = new User();
      $u->setUsername($_POST['username']);
      $u->setPassword($_POST['password']);
      $u->setAdmin(isset($_POST['role']));
      $u->save();
      return $u->getMessages();
    }

  class User {
    private $username;
    private $password;
    private $role;
    private $messages;
    private $salt;
    private $db;

    public function __construct(){
      $this->db = Singleton::getInstance()->getDb();
      $this->role = '';
      $this->messages = array();
    }

    public function setUsername($username){
      if(strlen($username) >= 4)
        $this->username = $username;
      else
        array_push($this->messages, 'Username is too short');
    }

    public function setPassword($password){
      if($this->validatesAgainstStupidPass($password))
        $this->salt = substr(md5(uniqid()), 0, 8);
        $this->password = base64_encode(pbkdf2($password, $this->salt));
    }<commit_msg>Fix if statement which would only cause the salt to be unset.<commit_after><?php
require(NICHT_PATH_LIB.'StupidPass.class.php');
require(NICHT_PATH_ROOT.'MysqliNichtAuthPbkdf2.class.php');

if(submitted_new_user_form())
  $tpl->assign('messages', handle_form_submission());

$tpl->assign('title', 'Administration');

  function submitted_new_user_form(){
    return isset($_POST['username']) && isset($_POST['password']);
  }

  function handle_form_submission(){
    $messages = array();
    if(!password_confirmation_matches())
      $messages[] = 'Passwords does not match.';
    else
      $messages = create_new_user();

    return $messages;
  }
    
    function password_confirmation_matches(){
      return $_POST['password'] == $_POST['password_confirmation'];
    }

    function create_new_user(){
      $u = new User();
      $u->setUsername($_POST['username']);
      $u->setPassword($_POST['password']);
      $u->setAdmin(isset($_POST['role']));
      $u->save();
      return $u->getMessages();
    }

  class User {
    private $username;
    private $password;
    private $role;
    private $messages;
    private $salt;
    private $db;

    public function __construct(){
      $this->db = Singleton::getInstance()->getDb();
      $this->role = '';
      $this->messages = array();
    }

    public function setUsername($username){
      if(strlen($username) >= 4)
        $this->username = $username;
      else
        array_push($this->messages, 'Username is too short');
    }

    public function setPassword($password){
      if($this->validatesAgainstStupidPass($password)) {
        $this->salt = substr(md5(uniqid()), 0, 8);
        $this->password = base64_encode(pbkdf2($password, $this->salt));
      }
    }
{'fraction_non_alphanumeric': 0.1648191365227538, 'fraction_numerical': 0.004667444574095682, 'mean_word_length': 3.5297225891677675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '7168857', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1039, 'n_words': 191}