Exemplo n.º 1
0
        public bool RegisterUser(string login, string password)
        {
            login = ClearLogin(login);
            if (login.Length < 6)
            {
                return(false);
            }

            password = password.Trim();
            password = EncryptPassword(password);

            using (var connection = new NpgsqlConnection(_sConnection)) {
                connection.Open();
                var command = new NpgsqlCommand {
                    Connection  = connection,
                    CommandText = @"INSERT INTO users (login, password) VALUES (@userLogin, @userPassword) RETURNING id",
                };
                command.Parameters.AddWithValue("@userLogin", login);
                // Соль хранится в начале пароля
                command.Parameters.AddWithValue("@userPassword", password);

                long id = (long)command.ExecuteScalar();
                NewUserAdded?.Invoke(id);
            }

            return(true);
        }
Exemplo n.º 2
0
 private void OnNewUserAdded(User user)
 {
     if (NewUserAdded == null)
     {
         return;
     }
     NewUserAdded.Invoke(user);
 }