Index: trunk/BNC/CHANGELOG.md
===================================================================
--- trunk/BNC/CHANGELOG.md	(revision 11152)
+++ trunk/BNC/CHANGELOG.md	(revision 11153)
@@ -82,4 +82,5 @@
 - CHANGED: Plot scripts (cmbPlot.pl, pppPlot.pl, compareSP3Plot.pl) delete only the images they created (cmbPlot.pl deleted all PNG files of the input directory)
 - CHANGED: Linux build with stack protector, bounds-checked std containers (_GLIBCXX_ASSERTIONS) and read-only relocations, independent of the distribution's compiler defaults
+- ADDED: Option 'Credentials files' (key credentialsFile): passwords of Ntrip Broadcasters can be kept in credentials files instead of the configuration file, in netrc format ('machine host[:port] login user password secret', default $NETRC or ~/.netrc) or BNC format ('host port|* user|- password'); several users per host, URLs without user stay anonymous, passwords in the configuration file are used as before
 
 ## 2.13.7 (2026-07-31)
Index: trunk/BNC/src/bnccredentials.cpp
===================================================================
--- trunk/BNC/src/bnccredentials.cpp	(revision 11153)
+++ trunk/BNC/src/bnccredentials.cpp	(revision 11153)
@@ -0,0 +1,341 @@
+/* -------------------------------------------------------------------------
+ * BKG NTRIP Client
+ * -------------------------------------------------------------------------
+ *
+ * Class:      bncCredentials
+ *
+ * Purpose:    Passwords from credentials files (netrc or BNC format)
+ *             instead of the configuration file
+ *
+ * Created:    31-Oct-2026
+ *
+ * Changes:
+ *
+ * -----------------------------------------------------------------------*/
+
+#include <QDateTime>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QMap>
+#include <QMutex>
+#include <QSet>
+
+#include "bnccredentials.h"
+#include "bnccore.h"
+#include "bncsettings.h"
+#include "bncutils.h"
+
+namespace {
+
+struct t_entry {
+  QString host;
+  int     port;     // 0: any port
+  bool    hasUser;
+  QString user;
+  QString password;
+};
+
+struct t_file {
+  t_file() : exists(false), size(-1), refused(false) {}
+  bool           exists;
+  QDateTime      modified;
+  qint64         size;
+  bool           refused;   // readable for others
+  QList<t_entry> entries;
+};
+
+QMutex                 _mutex;
+QMap<QString, t_file>  _files;
+QSet<QString>          _reported;
+
+// Log a message once per key
+void message(const QString& key, const QString& msg) {
+  if (!_reported.contains(key)) {
+    _reported.insert(key);
+    BNC_CORE->slotMessage(msg.toLatin1(), true);
+  }
+}
+
+// Split a line into tokens: white space separated, "..." quoted (with \"
+// and \\), '#' outside quotes starts a comment
+QStringList tokenize(const QString& line) {
+  QStringList tokens;
+  int ii = 0;
+  while (ii < line.size()) {
+    if (line[ii].isSpace()) {
+      ++ii;
+      continue;
+    }
+    if (line[ii] == '#') {
+      break;
+    }
+    QString token;
+    if (line[ii] == '"') {
+      for (++ii; ii < line.size() && line[ii] != '"'; ++ii) {
+        if (line[ii] == '\\' && ii + 1 < line.size()) {
+          ++ii;
+        }
+        token += line[ii];
+      }
+      ++ii; // closing quote
+    }
+    else {
+      for (; ii < line.size() && !line[ii].isSpace(); ++ii) {
+        token += line[ii];
+      }
+    }
+    tokens << token;
+  }
+  return tokens;
+}
+
+// "host" or "host:port"
+void hostAndPort(const QString& name, t_entry& entry) {
+  entry.host = name;
+  entry.port = 0;
+  int ic = name.lastIndexOf(':');
+  if (ic > 0) {
+    bool ok;
+    int port = name.mid(ic + 1).toInt(&ok);
+    if (ok && port > 0) {
+      entry.host = name.left(ic);
+      entry.port = port;
+    }
+  }
+}
+
+void parseNetrc(const QList<QStringList>& lines, t_file& file) {
+  t_entry* entry = 0;
+  bool     isDefault = false;
+  for (int iLine = 0; iLine < lines.size(); iLine++) {
+    const QStringList& tokens = lines[iLine];
+    for (int ii = 0; ii < tokens.size(); ii++) {
+      const QString& key = tokens[ii];
+      QString value = (ii + 1 < tokens.size()) ? tokens[ii + 1] : QString();
+      if (key == "machine") {
+        file.entries.append(t_entry());
+        entry = &file.entries.last();
+        entry->hasUser = false;
+        hostAndPort(value, *entry);
+        isDefault = false;
+        ++ii;
+      }
+      else if (key == "default") { // for all hosts: never used by BNC
+        entry = 0;
+        isDefault = true;
+      }
+      else if (key == "login" || key == "password" || key == "account") {
+        if (entry && !isDefault) {
+          if (key == "login") {
+            entry->hasUser = true;
+            entry->user = value;
+          }
+          else if (key == "password") {
+            entry->password = value;
+          }
+        }
+        ++ii;
+      }
+      else if (key == "macdef") { // macro definition up to an empty line
+        while (iLine + 1 < lines.size() && !lines[iLine + 1].isEmpty()) {
+          ++iLine;
+        }
+        break;
+      }
+    }
+  }
+}
+
+void parseBnc(const QString& fileName, const QList<QStringList>& lines,
+              const QList<int>& lineNumbers, t_file& file) {
+  for (int iLine = 0; iLine < lines.size(); iLine++) {
+    const QStringList& tokens = lines[iLine];
+    if (tokens.isEmpty()) {
+      continue;
+    }
+    bool ok = tokens.size() == 4;
+    t_entry entry;
+    entry.host = tokens.value(0);
+    if (tokens.value(1) == "*") {
+      entry.port = 0;
+    }
+    else {
+      bool okPort;
+      entry.port = tokens.value(1).toInt(&okPort);
+      ok = ok && okPort && entry.port > 0;
+    }
+    entry.hasUser = tokens.value(2) != "-";
+    entry.user = entry.hasUser ? tokens.value(2) : QString();
+    entry.password = tokens.value(3);
+    if (ok) {
+      file.entries.append(entry);
+    }
+    else {
+      message(fileName + QString(":%1").arg(lineNumbers[iLine]),
+              QString("Credentials file %1, line %2: not <host> <port> <user> <password>, ignored")
+              .arg(fileName).arg(lineNumbers[iLine]));
+    }
+  }
+}
+
+// Entries of a file, read again if it changed
+const t_file& readFile(const QString& fileName) {
+  t_file& file = _files[fileName];
+  QFileInfo info(fileName);
+  if (info.exists() == file.exists && (!file.exists ||
+      (info.lastModified() == file.modified && info.size() == file.size))) {
+    return file;
+  }
+  file = t_file();
+  file.exists = info.exists();
+  if (!file.exists) {
+    return file;
+  }
+  file.modified = info.lastModified();
+  file.size     = info.size();
+
+#ifndef Q_OS_WIN
+  if (info.permissions() & (QFile::ReadGroup | QFile::ReadOther)) {
+    file.refused = true;
+    message("perm:" + fileName,
+            QString("Credentials file %1 is readable for other users, not used (chmod 600)").arg(fileName));
+    return file;
+  }
+#endif
+
+  QFile inp(fileName);
+  if (!inp.open(QIODevice::ReadOnly | QIODevice::Text)) {
+    message("open:" + fileName, QString("Cannot read credentials file %1").arg(fileName));
+    return file;
+  }
+  QList<QStringList> lines;
+  QList<int>         lineNumbers;
+  int                lineNumber = 0;
+  while (!inp.atEnd()) {
+    QString line = QString::fromUtf8(inp.readLine());
+    ++lineNumber;
+    QStringList tokens = tokenize(line);
+    if (tokens.isEmpty() && line.trimmed().startsWith('#')) {
+      continue; // comment line, not the end of a netrc macro
+    }
+    lines << tokens;
+    lineNumbers << lineNumber;
+  }
+
+  // netrc, if the first token is a netrc keyword
+  QString first;
+  for (int ii = 0; ii < lines.size() && first.isEmpty(); ii++) {
+    first = lines[ii].value(0);
+  }
+  if (first == "machine" || first == "default" || first == "macdef") {
+    parseNetrc(lines, file);
+  }
+  else {
+    parseBnc(fileName, lines, lineNumbers, file);
+  }
+  return file;
+}
+
+bool sameUser(const t_entry& entry, const QString& user) {
+  return user.isEmpty() ? (!entry.hasUser || entry.user.isEmpty())
+                        : (entry.hasUser && entry.user == user);
+}
+
+}  // namespace
+
+// Credentials files: option 'credentialsFile' (comma separated), default
+// $NETRC or ~/.netrc (Windows: %HOME%\_netrc)
+////////////////////////////////////////////////////////////////////////////
+QStringList bncCredentials::fileNames() {
+  bncSettings settings;
+  QStringList names;
+  QStringList hlp = settings.value("credentialsFile").toString().split(',', Qt::SkipEmptyParts);
+  for (int ii = 0; ii < hlp.size(); ii++) {
+    QString name = hlp[ii].trimmed();
+    expandEnvVar(name);
+    if (name.startsWith("~/")) {
+      name = QDir::homePath() + name.mid(1);
+    }
+    if (!name.isEmpty()) {
+      names << name;
+    }
+  }
+  if (names.isEmpty()) {
+    QString netrc = QString::fromLocal8Bit(qgetenv("NETRC"));
+    if (netrc.isEmpty()) {
+#ifdef Q_OS_WIN
+      netrc = QDir::homePath() + "/_netrc";
+#else
+      netrc = QDir::homePath() + "/.netrc";
+#endif
+    }
+    names << netrc;
+  }
+  return names;
+}
+
+// Password of user at host:port
+////////////////////////////////////////////////////////////////////////////
+bool bncCredentials::password(const QString& host, int port, const QString& user,
+                              QString& password) {
+  QMutexLocker locker(&_mutex);
+  QStringList names = fileNames();
+  for (int iFile = 0; iFile < names.size(); iFile++) {
+    const t_file& file = readFile(names[iFile]);
+    if (file.refused) {
+      continue;
+    }
+    // exact port first, then entries for any port
+    for (int pass = 0; pass < 2; pass++) {
+      for (int ii = 0; ii < file.entries.size(); ii++) {
+        const t_entry& entry = file.entries[ii];
+        if (entry.host.compare(host, Qt::CaseInsensitive) == 0 &&
+            (pass == 0 ? (port > 0 && entry.port == port) : entry.port == 0) &&
+            sameUser(entry, user)) {
+          password = entry.password;
+          return true;
+        }
+      }
+    }
+  }
+  return false;
+}
+
+// Stream URL
+////////////////////////////////////////////////////////////////////////////
+void bncCredentials::complete(QUrl& url) {
+  if (url.userName().isEmpty()) {
+    return; // anonymous
+  }
+  QString user = QUrl::fromPercentEncoding(url.userName().toLatin1());
+  QString pass = url.password();
+  complete(url.host(), url.port(0), user, pass, false, true);
+  if (url.password().isEmpty() && !pass.isEmpty()) {
+    url.setPassword(pass, QUrl::DecodedMode);
+  }
+}
+
+// Upload or sourcetable
+////////////////////////////////////////////////////////////////////////////
+void bncCredentials::complete(const QString& host, int port, const QString& user,
+                              QString& password, bool anyUser, bool hint) {
+  QString account = (user.isEmpty() ? QString() : user + "@") + host + QString(":%1").arg(port);
+  if (!password.isEmpty()) {
+    if (hint) {
+      QMutexLocker locker(&_mutex);
+      message("config:" + account,
+              QString("%1: password in the configuration file, it can be moved to a credentials file "
+                      "(option 'credentialsFile', default ~/.netrc)").arg(account));
+    }
+    return;
+  }
+  if (user.isEmpty() && !anyUser) {
+    return;
+  }
+  if (!bncCredentials::password(host, port, user, password)) {
+    QMutexLocker locker(&_mutex);
+    message("none:" + account, QString("%1: no password in the configuration file nor in %2")
+            .arg(account).arg(fileNames().join(", ")));
+  }
+}
Index: trunk/BNC/src/bnccredentials.h
===================================================================
--- trunk/BNC/src/bnccredentials.h	(revision 11153)
+++ trunk/BNC/src/bnccredentials.h	(revision 11153)
@@ -0,0 +1,34 @@
+#ifndef BNCCREDENTIALS_H
+#define BNCCREDENTIALS_H
+
+#include <QString>
+#include <QStringList>
+#include <QUrl>
+
+// Passwords from credentials files instead of the configuration file
+// (option 'credentialsFile', default $NETRC or ~/.netrc). Two formats,
+// detected per file:
+//   netrc:  machine <host>[:<port>] login <user> password <password>
+//   BNC:    <host> <port|*> <user|-> <password>      (one entry per line)
+// Tokens are separated by white space, may be quoted ("..."), '#' starts a
+// comment. An entry for the exact port is preferred, the netrc 'default'
+// entry is never used.
+class bncCredentials {
+ public:
+  // Password of user (empty: entry without user) at host:port
+  static bool password(const QString& host, int port, const QString& user,
+                       QString& password);
+
+  // Stream URL: a user without password gets it from the credentials files;
+  // a URL without user stays anonymous
+  static void complete(QUrl& url);
+
+  // Upload or sourcetable: an empty password is taken from the credentials
+  // files (also for an empty user, e.g. Ntrip Version 1 upload if 'anyUser')
+  static void complete(const QString& host, int port, const QString& user,
+                       QString& password, bool anyUser, bool hint);
+
+  static QStringList fileNames();
+};
+
+#endif
Index: trunk/BNC/src/bncgetthread.cpp
===================================================================
--- trunk/BNC/src/bncgetthread.cpp	(revision 11152)
+++ trunk/BNC/src/bncgetthread.cpp	(revision 11153)
@@ -65,4 +65,5 @@
 #include "bncnetqueryudp.h"
 #include "bncnetqueryudp0.h"
+#include "bnccredentials.h"
 #include "bncnetquerys.h"
 #include "bncsettings.h"
@@ -95,4 +96,6 @@
   _rawFile = 0;
   _mountPoint   = mountPoint;
+  _requestUrl   = mountPoint;
+  bncCredentials::complete(_requestUrl); // password from a credentials file
   _staID        = mountPoint.path().mid(1).toLatin1();
   _format       = format;
@@ -356,5 +359,5 @@
   msleep(100); //sleep 0.1 sec
 
-  _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, _nmea,
+  _decoder->initRinex(_staID, _requestUrl, _latitude, _longitude, _nmea,
       _ntripVersion);
 
@@ -768,5 +771,5 @@
     if (_nmea == "yes") {
       if (_serialNMEA == MANUAL_NMEA) {
-        _query->startRequest(_mountPoint, _manualNMEAString);
+        _query->startRequest(_requestUrl, _manualNMEAString);
         _lastNMEA = QDateTime::currentDateTime();
       } else if (_serialNMEA == AUTO_NMEA) {
@@ -783,5 +786,5 @@
               if (i2 != -1 && data.size() > i2 + 1) {
                 QByteArray gga = data.mid(i1, i2 - i1 + 3);
-                _query->startRequest(_mountPoint, gga);
+                _query->startRequest(_requestUrl, gga);
                 _lastNMEA = QDateTime::currentDateTime();
               }
@@ -791,5 +794,5 @@
       }
     } else {
-      _query->startRequest(_mountPoint, "");
+      _query->startRequest(_requestUrl, "");
     }
 
Index: trunk/BNC/src/bncgetthread.h
===================================================================
--- trunk/BNC/src/bncgetthread.h	(revision 11152)
+++ trunk/BNC/src/bncgetthread.h	(revision 11153)
@@ -109,5 +109,6 @@
    GPSDecoder*                _decoder;
    bncNetQuery*               _query;
-   QUrl                       _mountPoint;
+   QUrl                       _mountPoint;   // as configured (identifies the stream)
+   QUrl                       _requestUrl;   // with password from a credentials file
    QByteArray                 _staID;
    QByteArray                 _format;
Index: trunk/BNC/src/bnchelp.html
===================================================================
--- trunk/BNC/src/bnchelp.html	(revision 11152)
+++ trunk/BNC/src/bnchelp.html	(revision 11153)
@@ -2692,4 +2692,27 @@
     and feed in manipulated data. The ignored errors are logged. Better save the CA certificate of the Ntrip
     Broadcaster in the 'Path to SSL certificates' directory.
+  </p>
+  <p>
+    Passwords of Ntrip Broadcasters can be kept in 'Credentials files' instead of BNC's configuration file, which
+    then contains no secrets and can be passed on. Give the user name without password in the stream's URL, e.g.
+    '//user@products.igs-ip.net:443/SSRA00BKG1', or in the upload settings (empty password). BNC takes the password
+    from the first matching entry of the credentials files. Streams without user name are retrieved without
+    authentication, even if a file contains an entry for that host. A password still given in the configuration
+    file is used as before (with a hint in the logfile), so configurations can be changed step by step.
+  </p>
+  <p>
+    Two file formats are accepted and detected from the content:
+  <ul>
+    <li>netrc, as used by curl, wget or git: 'machine products.igs-ip.net login user password secret'. The machine
+      may also be given as 'host:port' for an account that applies to one port only. The netrc 'default' entry is
+      not used.</li>
+    <li>BNC: one entry per line '&lt;host&gt; &lt;port&gt; &lt;user&gt; &lt;password&gt;', port '*' for any port,
+      user '-' for an entry without user (Ntrip Version 1 upload).</li>
+  </ul>
+    Several users per host are distinguished by the user name. An entry for the exact port is preferred over one
+    for any port. Words containing blanks are quoted: "my secret". A '#' starts a comment. Several files can be
+    given, separated by commas; default is the file named in the environment variable NETRC, otherwise ~/.netrc.
+    A file readable for other users is not used (chmod 600). Note that a password containing '%' followed by two
+    hexadecimal digits is not supported, in the configuration file neither.
   </p>
   <p><img src="IMG/Figure07.png" width=800 /></p>
Index: trunk/BNC/src/bncmain.cpp
===================================================================
--- trunk/BNC/src/bncmain.cpp	(revision 11152)
+++ trunk/BNC/src/bncmain.cpp	(revision 11153)
@@ -136,4 +136,5 @@
         "   sslClientCertPath {Full path to client SSL certificates [character string]}\n"
         "   sslIgnoreErrors   {Ignore SSL authorization errors [integer number: 0=no,2=yes]}\n"
+        "   credentialsFile   {Credentials files, netrc or BNC format, default $NETRC or ~/.netrc [character string, comma separated list]}\n"
         "\n"
         "General Panel keys:\n"
Index: trunk/BNC/src/bncsettings.cpp
===================================================================
--- trunk/BNC/src/bncsettings.cpp	(revision 11152)
+++ trunk/BNC/src/bncsettings.cpp	(revision 11153)
@@ -75,4 +75,5 @@
         setValue_p("sslClientCertPath", "");
         setValue_p("sslIgnoreErrors", "0");
+        setValue_p("credentialsFile", "");
         // General
         setValue_p("logFile", "");
Index: trunk/BNC/src/bnctabledlg.cpp
===================================================================
--- trunk/BNC/src/bnctabledlg.cpp	(revision 11152)
+++ trunk/BNC/src/bnctabledlg.cpp	(revision 11153)
@@ -47,4 +47,5 @@
 
 #include "bnctabledlg.h"
+#include "bnccredentials.h"
 #include "bncgetthread.h"
 #include "bncnetqueryv1.h"
@@ -238,5 +239,7 @@
   }
   url.setUserName(QUrl::toPercentEncoding(casterUser));
-  url.setPassword(QUrl::toPercentEncoding(casterPassword));
+  QString password = casterPassword; // empty: from a credentials file
+  bncCredentials::complete(casterHost, casterPort, casterUser, password, false, false);
+  url.setPassword(QUrl::toPercentEncoding(password));
   QByteArray outData;
   query->waitForRequestResult(url, outData);
Index: trunk/BNC/src/bncwindow.cpp
===================================================================
--- trunk/BNC/src/bncwindow.cpp	(revision 11152)
+++ trunk/BNC/src/bncwindow.cpp	(revision 11153)
@@ -194,4 +194,5 @@
   _sslIgnoreErrorsCheckBox->setCheckState(Qt::CheckState(
                                                          settings.value("sslIgnoreErrors").toInt()));
+  _credentialsFileLineEdit = new QLineEdit(settings.value("credentialsFile").toString());
 
   // General Options
@@ -828,6 +829,9 @@
   pLayout->addWidget(new QLabel("Ignore SSL authorization errors"), 5, 0);
   pLayout->addWidget(_sslIgnoreErrorsCheckBox, 5, 1, 1, 10);
-  pLayout->addWidget(new QLabel(""), 6, 1);
-  pLayout->setRowStretch(6, 999);
+  pLayout->addWidget(new QLabel("Credentials files"), 6, 0);
+  pLayout->addWidget(_credentialsFileLineEdit, 6, 1, 1, 10);
+  pLayout->addWidget(new QLabel("Default:  $NETRC or ~/.netrc"), 6, 11, 1, 20);
+  pLayout->addWidget(new QLabel(""), 7, 1);
+  pLayout->setRowStretch(7, 999);
 
   pgroup->setLayout(pLayout);
@@ -1558,4 +1562,5 @@
   _sslCaCertPathLineEdit->setWhatsThis(tr("<p>Communication with an Ntrip Broadcaster over SSL requires the exchange of server certificates. Specify the path to a directory where you save CA certificates on your system. </p><p>BNC creates from *.crt and *.pem files a CA certificate database, which is used by the socket during the handshake phase to validate the peer's certificate. </p><p>Note that SSL communication is usually done over port 443. <i>[key: sslCaCertPath]</i></p>"));
   _sslClientCertPathLineEdit->setWhatsThis(tr("<p>Two-sided communication with an Ntrip Broadcaster over SSL requires in addition the exchange of client certificates. Specify the full path to the client certificates on your system.</p><p></p><p>The file naming convention for client certificates in BNC is as follows: &lt;hostname&gt;.&lt;port&gt;.crt for the certificate and &lt;hostname&gt;.&lt;port&gt;.key for the private key, where &lt;hostname&gt; is without https://. </p><p> If available, the client or personal authentication certificate is presented to the peer during the SSL handshake process. Password protected key files are not supported. </p><p>Don't try communication via two sided SSL if you are not sure whether this is supported by the involved Ntrip Broadcaster. </p><p>Note that SSL communication is usually done over port 443. <i>[key: sslClientCertPath]</i></p>"));
+  _credentialsFileLineEdit->setWhatsThis(tr("<p>Passwords of Ntrip Broadcasters can be kept in credentials files instead of the configuration file: give the user name without password in the stream's URL (e.g. '//user@products.igs-ip.net:443/SSRA00BKG1') or in the upload settings (empty password). BNC then takes the password from the first matching entry of these files. Streams without user name are retrieved without authentication.</p><p>Two formats are accepted, detected from the file content:<br>netrc: 'machine products.igs-ip.net login user password secret', where the machine may also be given as 'host:port';<br>BNC: one entry per line '&lt;host&gt; &lt;port&gt; &lt;user&gt; &lt;password&gt;', port '*' for any port, user '-' for an entry without user (Ntrip Version 1 upload).</p><p>An entry for the exact port is preferred. Several files can be given, separated by commas; default is the file named in the environment variable NETRC or ~/.netrc. A file readable for other users is not used. A password still given in the configuration file is used as before. <i>[key: credentialsFile]</i></p>"));
   _sslIgnoreErrorsCheckBox->setWhatsThis(tr("<p>Tick 'Ignore SSL authorization errors' to accept a server certificate that cannot be verified, e.g. a self-signed certificate or one issued for another host name. The connection is then still encrypted, but the server is not authenticated: anybody able to intercept the connection may receive your user name and password and feed in manipulated data. The ignored errors are logged. Better save the CA certificate of the Ntrip Broadcaster in the 'Path to SSL certificates' directory. <i>[key: sslIgnoreErrors]</i></p>"));
 
@@ -1874,4 +1879,5 @@
   delete _sslClientCertPathLineEdit;
   delete _sslIgnoreErrorsCheckBox;
+  delete _credentialsFileLineEdit;
   delete _logFileLineEdit;
   delete _rawOutFileLineEdit;
@@ -2088,4 +2094,5 @@
   settings.setValue("sslClientCertPath", _sslClientCertPathLineEdit->text());
   settings.setValue("sslIgnoreErrors", _sslIgnoreErrorsCheckBox->checkState());
+  settings.setValue("credentialsFile", _credentialsFileLineEdit->text());
 
   QMessageBox msgBox;
@@ -2404,4 +2411,5 @@
   settings.setValue("sslClientCertPath", _sslClientCertPathLineEdit->text());
   settings.setValue("sslIgnoreErrors", _sslIgnoreErrorsCheckBox->checkState());
+  settings.setValue("credentialsFile", _credentialsFileLineEdit->text());
   // General
   settings.setValue("logFile", _logFileLineEdit->text());
Index: trunk/BNC/src/bncwindow.h
===================================================================
--- trunk/BNC/src/bncwindow.h	(revision 11152)
+++ trunk/BNC/src/bncwindow.h	(revision 11153)
@@ -141,4 +141,5 @@
     QLineEdit* _sslClientCertPathLineEdit;
     QCheckBox* _sslIgnoreErrorsCheckBox;
+    QLineEdit* _credentialsFileLineEdit;
     QLineEdit* _outFileLineEdit;
     QLineEdit* _outPortLineEdit;
Index: trunk/BNC/src/src.pri
===================================================================
--- trunk/BNC/src/src.pri	(revision 11152)
+++ trunk/BNC/src/src.pri	(revision 11153)
@@ -67,5 +67,5 @@
           bncoutf.h bncclockrinex.h bncsp3.h bncsinextro.h            \
           bncbiassinex.h                                              \
-          bncbytescounter.h bncsslconfig.h reqcdlg.h                  \
+          bncbytescounter.h bncsslconfig.h bnccredentials.h reqcdlg.h                  \
           ephemeris.h t_prn.h satObs.h                                \
           upload/bncrtnetdecoder.h upload/bncuploadcaster.h           \
@@ -110,5 +110,5 @@
           bncbiassinex.cpp                                            \
           ephemeris.cpp t_prn.cpp satObs.cpp                          \
-          bncbytescounter.cpp bncsslconfig.cpp reqcdlg.cpp            \
+          bncbytescounter.cpp bncsslconfig.cpp bnccredentials.cpp reqcdlg.cpp            \
           upload/bncrtnetdecoder.cpp upload/bncuploadcaster.cpp       \
           upload/bncrawuploadcaster.cpp                               \
Index: trunk/BNC/src/upload/bncuploadcaster.cpp
===================================================================
--- trunk/BNC/src/upload/bncuploadcaster.cpp	(revision 11152)
+++ trunk/BNC/src/upload/bncuploadcaster.cpp	(revision 11153)
@@ -22,4 +22,5 @@
 #include "bncsettings.h"
 #include "bncsslconfig.h"
+#include "bnccredentials.h"
 
 using namespace std;
@@ -46,4 +47,8 @@
   _userName = userName;
   _password = password;
+  if (!_mountpoint.isEmpty() && !_casterOutHost.isEmpty()) {
+    // empty password: from a credentials file, also without user (Ntrip Version 1)
+    bncCredentials::complete(_casterOutHost, _casterOutPort, _userName, _password, true, true);
+  }
   _outSocket = 0;
   _sOpenTrial = 0;
Index: trunk/BNC/tests/README.md
===================================================================
--- trunk/BNC/tests/README.md	(revision 11152)
+++ trunk/BNC/tests/README.md	(revision 11153)
@@ -32,4 +32,5 @@
 | `tools/ssl_check.py` | TLS checks of the Ntrip 2s client and upload (not part of `run_tests.py`) |
 | `tools/net_check.py` | UDP/RTP sender filter and upload status checks on loopback (not part of `run_tests.py`) |
+| `tools/cred_check.py` | credentials files (`~/.netrc`, BNC format) for download and upload (not part of `run_tests.py`) |
 | `work/` | scratch output, not versioned |
 
@@ -179,4 +180,19 @@
 as broken. Takes about 2 min.
 
+## Credentials check
+
+```
+tests/tools/cred_check.py [--bnc PATH]
+```
+
+BNC against `tools/fakecaster.py --auth user:password` (other credentials
+rejected), each scenario with its own `HOME`: password in the configuration
+file (hint logged), `~/.netrc` with two users for the host, `$NETRC` with
+`machine host:port` preferred, BNC format file (`credentialsFile`) with exact
+port preferred over `*` and a quoted password, URL without user (no
+credentials sent), user without entry, `~/.netrc` readable for others and the
+netrc `default` entry (not used), Ntrip 1 download, Ntrip 2 upload and
+Ntrip 1 upload without user. Takes about 2 min.
+
 ## Adding a replay case
 
Index: trunk/BNC/tests/tools/cred_check.py
===================================================================
--- trunk/BNC/tests/tools/cred_check.py	(revision 11153)
+++ trunk/BNC/tests/tools/cred_check.py	(revision 11153)
@@ -0,0 +1,187 @@
+#!/usr/bin/env python3
+"""Checks of the credentials files (option credentialsFile, ~/.netrc) with
+BNC as Ntrip client and as uploading source against tools/fakecaster.py
+(--auth: only the expected user and password are accepted). Every scenario
+runs with its own HOME directory, so ~/.netrc is under control.
+
+    tests/tools/cred_check.py [--bnc PATH]      exit code 1 if a check fails
+
+Download (Ntrip 2 unless noted):
+  password in the configuration file (as before, hint in the log)
+  user only, ~/.netrc with two users for the host (and a macdef)
+  $NETRC: entry 'machine host:port' preferred over 'machine host'
+  BNC format (credentialsFile): exact port preferred over '*', quoted password
+  URL without user: no credentials sent although ~/.netrc has the host
+  user without entry: logged, rejected by the caster
+  ~/.netrc readable for others: not used (logged)
+  netrc 'default' entry: not used
+  Ntrip 1 with ~/.netrc
+Upload:
+  Ntrip 2, user with empty password, BNC format file
+  Ntrip 1, no user and empty password, BNC format entry with user '-'
+"""
+
+import argparse
+import glob
+import os
+import shutil
+import subprocess
+import sys
+import time
+
+TOOLS = os.path.dirname(os.path.abspath(__file__))
+TESTS = os.path.dirname(TOOLS)
+ROOT = os.path.dirname(TESTS)
+WORK = os.path.join(TESTS, "work", "cred_check")
+SERVE_RAW = os.path.join(TESTS, "data", "crafted_limits.raw")
+UPLOAD_RAW = os.path.join(TESTS, "data", "upload_rtnet_5min.raw")
+
+
+def run(bnc, name, port, auth, bnc_args, files=None, env_extra=None, upload=False):
+    """Fake caster on 127.0.0.1:port, BNC with HOME=<work>/home; returns
+    (caster output, BNC log)."""
+    d = os.path.join(WORK, name)
+    home = os.path.join(d, "home")
+    os.makedirs(os.path.join(d, "Output"))
+    os.makedirs(home)
+    os.symlink(os.path.join(ROOT, "Example_Configs", "Input"), os.path.join(d, "Input"))
+    for path, (text, mode) in (files or {}).items():
+        path = path.replace("~", home)
+        with open(path, "w") as f:
+            f.write(text.replace("PORT", str(port)))
+        os.chmod(path, mode)
+    caster = [sys.executable, "-I", os.path.join(TOOLS, "fakecaster.py"), "--port", str(port),
+              "--out", os.path.join(d, "Output", "upload.raw"), "--time", "2026-10-01T09:33:00",
+              "--timeout", "6"]
+    if not upload:
+        caster += ["--serve", SERVE_RAW]
+    for a in auth:
+        caster += ["--auth", a]
+    fc = subprocess.Popen(caster, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
+    fc.stdout.readline()  # "listening"
+    env = dict(os.environ, QT_QPA_PLATFORM="offscreen", LC_ALL="C", TZ="UTC", HOME=home)
+    env.pop("NETRC", None)
+    env.update({k: v.replace("~", home) for k, v in (env_extra or {}).items()})
+    args = [a.replace("~", home).replace("PORT", str(port)) for a in bnc_args]
+    cmd = [bnc, "--nw", "--platform", "offscreen"] + args
+    with open(os.path.join(d, "bnc.out"), "wb") as out:
+        if upload:
+            subprocess.run(cmd, cwd=d, stdout=out, stderr=subprocess.STDOUT, env=env, timeout=300)
+        else:
+            p = subprocess.Popen(cmd, cwd=d, stdout=out, stderr=subprocess.STDOUT, env=env)
+            time.sleep(8)
+            p.send_signal(2)
+            p.wait(30)
+    out = fc.communicate(timeout=120)[0]
+    with open(os.path.join(d, "caster.out"), "w") as f:
+        f.write(out)
+    log = "".join(open(f, errors="replace").read() for f in glob.glob(os.path.join(d, "Output", "*.log*")))
+    return out, log
+
+
+def download(bnc, name, port, url_user, auth, files=None, env_extra=None, extra=(), version="2"):
+    mp = "//%s127.0.0.1:%d/TEST RTCM_3 DEU 50 8 no %s" % (url_user, port, version)
+    return run(bnc, name, port, auth,
+               ["--conf", os.path.join(ROOT, "Example_Configs", "22_Empty.bnc"),
+                "-key", "mountPoints", mp, "-key", "logFile", "Output/bnc.log"] + list(extra),
+               files, env_extra)
+
+
+def upload(bnc, name, port, version, user, auth, files, extra=()):
+    mp = "127.0.0.1,%d,CLOCK,%s,%s,,IGS20,IGS-SSR,0,,,,,,,0 byte(s)," % (port, version, user)
+    return run(bnc, name, port, auth,
+               ["--conf", os.path.join(ROOT, "Example_Configs", "16_Upload.bnc"),
+                "--file", UPLOAD_RAW, "-key", "uploadMountpointsOut", mp] + list(extra),
+               files, upload=True)
+
+
+def main():
+    ap = argparse.ArgumentParser(description=__doc__,
+                                 formatter_class=argparse.RawDescriptionHelpFormatter)
+    ap.add_argument("--bnc", default=os.path.join(ROOT, "bnc"))
+    args = ap.parse_args()
+    bnc = os.path.abspath(args.bnc)
+    shutil.rmtree(WORK, ignore_errors=True)
+    failed = 0
+
+    def check(name, ok, caster):
+        nonlocal failed
+        lines = [l for l in caster.splitlines() if l.startswith(("auth", "served", "received"))]
+        summary = ", ".join(sorted(set(lines)))
+        print("%-6s %-46s %s" % ("PASS" if ok else "FAIL", name, summary), flush=True)
+        failed += not ok
+
+    def served(c):
+        return any(l.startswith("served ") and int(l.split()[1]) > 0 for l in c.splitlines())
+
+    def rejected(c):
+        return any(l.startswith("auth ") and l.endswith(" rejected") for l in c.splitlines())
+
+    def received(c):
+        return any(l.startswith("received ") and int(l.split()[1]) > 0 for l in c.splitlines())
+
+    netrc_two_users = ("macdef init\ncd /tmp\n\n"
+                       "# two accounts on the same caster\n"
+                       "machine 127.0.0.1 login other password x\n"
+                       "machine 127.0.0.1 login bnc password right\n")
+
+    c, log = download(bnc, "config_password", 21301, "bnc:right@", ["bnc:right"])
+    check("download: password in the configuration file", served(c) and "auth bnc accepted" in c
+          and "password in the configuration file" in log, c)
+
+    c, log = download(bnc, "netrc_two_users", 21302, "bnc@", ["bnc:right"],
+                      {"~/.netrc": (netrc_two_users, 0o600)})
+    check("download: ~/.netrc, two users for the host", served(c) and "auth bnc accepted" in c
+          and not rejected(c) and "configuration file" not in log, c)
+
+    c, log = download(bnc, "netrc_port", 21303, "bnc@", ["bnc:right"],
+                      {"~/other_netrc": ("machine 127.0.0.1 login bnc password wrong\n"
+                                         "machine 127.0.0.1:PORT login bnc password right\n", 0o600)},
+                      {"NETRC": "~/other_netrc"})
+    check("download: $NETRC, machine host:port preferred", served(c) and not rejected(c), c)
+
+    c, log = download(bnc, "bnc_format", 21304, "bnc@", ["bnc:my secret"],
+                      {"~/bnc.credentials": ("# host port user password\n"
+                                             "127.0.0.1  *    bnc  wrong\n"
+                                             "127.0.0.1  PORT bnc  \"my secret\"\n", 0o600)},
+                      extra=["-key", "credentialsFile", "~/bnc.credentials"])
+    check("download: BNC format, exact port, quoted", served(c) and not rejected(c), c)
+
+    c, log = download(bnc, "anonymous", 21305, "", [],
+                      {"~/.netrc": (netrc_two_users, 0o600)})
+    check("download: URL without user stays anonymous", served(c) and "auth none" in c
+          and "auth bnc" not in c and "auth other" not in c, c)
+
+    c, log = download(bnc, "no_entry", 21306, "bnc@", ["bnc:right"],
+                      {"~/.netrc": ("machine 127.0.0.1 login other password x\n", 0o600)})
+    check("download: no entry for the user", not served(c) and "auth bnc rejected" in c
+          and "no password" in log, c)
+
+    c, log = download(bnc, "netrc_readable", 21307, "bnc@", ["bnc:right"],
+                      {"~/.netrc": ("machine 127.0.0.1 login bnc password right\n", 0o644)})
+    check("download: ~/.netrc readable for others", not served(c) and "readable for other users" in log, c)
+
+    c, log = download(bnc, "netrc_default", 21308, "bnc@", ["bnc:right"],
+                      {"~/.netrc": ("default login bnc password right\n", 0o600)})
+    check("download: netrc default entry not used", not served(c) and "no password" in log, c)
+
+    c, log = download(bnc, "ntrip1", 21309, "bnc@", ["bnc:right"],
+                      {"~/.netrc": (netrc_two_users, 0o600)}, version="1")
+    check("download: Ntrip 1, ~/.netrc", served(c) and "auth bnc accepted" in c and not rejected(c), c)
+
+    c, log = upload(bnc, "upload_v2", 21310, "2", "bnc", ["bnc:up2"],
+                    {"~/bnc.credentials": ("127.0.0.1 PORT bnc up2\n", 0o600)},
+                    ["-key", "credentialsFile", "~/bnc.credentials"])
+    check("upload: Ntrip 2, password from file", received(c) and not rejected(c), c)
+
+    c, log = upload(bnc, "upload_v1", 21311, "1", "", [":up1"],
+                    {"~/bnc.credentials": ("127.0.0.1 PORT - up1\n", 0o600)},
+                    ["-key", "credentialsFile", "~/bnc.credentials"])
+    check("upload: Ntrip 1, entry without user", received(c) and not rejected(c), c)
+
+    print("%d check(s) failed, details in %s" % (failed, os.path.relpath(WORK, ROOT)))
+    return 1 if failed else 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())
Index: trunk/BNC/tests/tools/fakecaster.py
===================================================================
--- trunk/BNC/tests/tools/fakecaster.py	(revision 11152)
+++ trunk/BNC/tests/tools/fakecaster.py	(revision 11153)
@@ -16,9 +16,13 @@
 a GET request (BNC as Ntrip client) is answered with the RTCM bytes of the
 given raw file. With --reply an upload is answered with this text instead
-of the 200 status (e.g. a rejection), and the connection is closed. Failed
+of the 200 status (e.g. a rejection), and the connection is closed. With
+--auth user:password (repeatable, ':password' for an Ntrip 1 upload) only
+these credentials are accepted, others get 401 / 'ERROR - Bad Password'.
+The user received ("-" without user, "none" without credentials) and failed
 TLS handshakes are reported on stdout.
 """
 
 import argparse
+import base64
 import os
 import socket
@@ -70,5 +74,20 @@
 
 
-def serve(conn, store, timeout, tls=None, served=None, reply=None):
+def credentials(header):
+    """(user, password) of a request header, None without credentials."""
+    lines = header.split(b"\r\n")
+    if lines[0].startswith(b"SOURCE"):
+        parts = lines[0].split(b" ")
+        return "", parts[1].decode("latin-1") if len(parts) > 1 else ""
+    for line in lines[1:]:
+        key, _, value = line.partition(b":")
+        value = value.strip()
+        if key.strip().lower() == b"authorization" and value.lower().startswith(b"basic "):
+            user, _, password = base64.b64decode(value[6:]).decode("latin-1").partition(":")
+            return user, password
+    return None
+
+
+def serve(conn, store, timeout, tls=None, served=None, reply=None, auth=None):
     conn.settimeout(timeout)
     buf = b""
@@ -88,7 +107,19 @@
         header, _, pending = buf.partition(b"\r\n\r\n")
         chunked = b"chunked" in header.lower()
+        cred = credentials(header)
+        ok = auth is None or cred in auth
+        print("auth %s %s" % ("none" if cred is None else (cred[0] or "-"),
+                              "accepted" if ok else "rejected"), flush=True)
+        if not ok:
+            conn.sendall(b"ERROR - Bad Password\r\n" if header.startswith(b"SOURCE")
+                         else b"HTTP/1.1 401 Unauthorized\r\n\r\n")
+            store.rejected += 1
+            return
         if header.startswith(b"GET") and served is not None:
-            conn.sendall(b"HTTP/1.1 200 OK\r\nNtrip-Version: Ntrip/2.0\r\n"
-                         b"Content-Type: gnss/data\r\nConnection: close\r\n\r\n" + served)
+            if b"ntrip-version" in header.lower():
+                conn.sendall(b"HTTP/1.1 200 OK\r\nNtrip-Version: Ntrip/2.0\r\n"
+                             b"Content-Type: gnss/data\r\nConnection: close\r\n\r\n" + served)
+            else:  # Ntrip 1
+                conn.sendall(b"ICY 200 OK\r\n\r\n" + served)
             store.served += len(served)
             return
@@ -134,4 +165,6 @@
     ap.add_argument("--tls-client-ca", help="require a client certificate of this CA")
     ap.add_argument("--serve", help="raw file whose RTCM bytes are sent on GET")
+    ap.add_argument("--auth", action="append",
+                    help="accepted user:password (repeatable), others rejected")
     ap.add_argument("--reply", help="answer to uploads instead of 200 ('\\r\\n' escapes allowed)")
     args = ap.parse_args()
@@ -147,4 +180,7 @@
     if args.reply is not None:
         reply = args.reply.encode("latin-1").decode("unicode_escape").encode("latin-1")
+    auth = None
+    if args.auth:
+        auth = [tuple(a.split(":", 1)) for a in args.auth]
     served = None
     if args.serve:
@@ -166,5 +202,5 @@
         except socket.timeout:
             break
-        t = threading.Thread(target=serve, args=(conn, store, args.timeout, tls, served, reply),
+        t = threading.Thread(target=serve, args=(conn, store, args.timeout, tls, served, reply, auth),
                              daemon=True)
         t.start()
@@ -177,6 +213,6 @@
     if served is not None:
         print("served %d bytes" % store.served, flush=True)
-    if reply is not None:
-        print("%d upload(s) answered with --reply" % store.rejected, flush=True)
+    if reply is not None or auth is not None:
+        print("%d connection(s) rejected" % store.rejected, flush=True)
     return 0
 
