Allow blank usernames, asking for one at connect time instead

Closes #21. SSH and RDP profiles previously hard-required a username
to even save the profile; that validation is dropped, and
SessionTab::requestConnectOptions() now prompts for it at connect
time when blank, reusing the existing password-prompt bar in
unmasked mode -- the same pattern already used for a blank password.

VNC's username is trickier: most VNC servers never use one (plain VNC
Authentication and no-auth don't), only the two Apple auth schemes
(security types 30/33) do, and which auth method gets used isn't known
until mid-connection, after the server's security-type list has been
negotiated -- too late for the pre-connect prompt SSH/RDP uses. Adds a
new async request/response pair to SessionBackend, usernameRequested()
signal / provideUsername() slot, mirroring the existing SSH host-key-
confirmation pattern. VncSessionBackend pauses its state machine right
before computing an Apple-auth response if no username is available --
without consuming the already-buffered prime/host-key bytes, so
resuming re-parses them identically -- emits the request, and resumes
via provideUsername(). Cancelling (or submitting blank) fails the
connection cleanly instead of sending Apple auth an empty username.

The username is kept on the tab's in-memory profile copy for its
lifetime, not written back to the saved profile, matching how
passwords are already handled.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 08:01:57 -06:00
co-authored by Claude Sonnet 5
parent d7f9d4966b
commit 776db5ec04
8 changed files with 221 additions and 16 deletions
+43 -1
View File
@@ -215,6 +215,11 @@ SessionTab::SessionTab(const Profile& profile,
m_backend,
&SessionBackend::setClipboardText,
Qt::QueuedConnection);
connect(this,
&SessionTab::requestProvideUsername,
m_backend,
&SessionBackend::provideUsername,
Qt::QueuedConnection);
connect(m_backend,
&SessionBackend::stateChanged,
@@ -241,6 +246,11 @@ SessionTab::SessionTab(const Profile& profile,
this,
&SessionTab::onBackendHostKeyConfirmationRequested,
Qt::QueuedConnection);
connect(m_backend,
&SessionBackend::usernameRequested,
this,
&SessionTab::onBackendUsernameRequested,
Qt::QueuedConnection);
connect(m_backend,
&SessionBackend::frameUpdated,
this,
@@ -714,6 +724,16 @@ void SessionTab::onBackendHostKeyConfirmationRequested(const QString& prompt)
emit requestHostKeyConfirmation(reply == QMessageBox::Yes);
}
void SessionTab::onBackendUsernameRequested(const QString& prompt)
{
showPasswordPrompt(
prompt.isEmpty() ? QStringLiteral("Username for %1:").arg(m_profile.host) : prompt,
[this](std::optional<QString> username) {
emit requestProvideUsername(username.value_or(QString()).trimmed());
},
false);
}
void SessionTab::onBackendRemoteClipboardTextChanged(const QString& text)
{
if (text == m_lastSyncedClipboardText) {
@@ -983,6 +1003,26 @@ void SessionTab::requestConnectOptions(
const bool isRdp = m_profile.protocol.compare(QStringLiteral("RDP"), Qt::CaseInsensitive) == 0;
const bool isVnc = m_profile.protocol.compare(QStringLiteral("VNC"), Qt::CaseInsensitive) == 0;
// SSH and RDP always need a username; a profile is now allowed to
// leave it blank (see profile_dialog.cpp) and get asked here instead,
// the same way a blank password is already handled below. The value
// is kept on this in-memory m_profile copy for the rest of the tab's
// lifetime, not written back to the saved profile.
if ((isSsh || isRdp) && m_profile.username.trimmed().isEmpty()) {
showPasswordPrompt(
QStringLiteral("%1 username for %2:").arg(m_profile.protocol, m_profile.host),
[this, callback](std::optional<QString> username) {
if (!username.has_value() || username->trimmed().isEmpty()) {
callback(std::nullopt);
return;
}
m_profile.username = username->trimmed();
requestConnectOptions(callback);
},
false);
return;
}
if (isVnc) {
// Unlike RDP, an empty password is allowed through: some VNC
// servers (no-auth) don't need one at all, and there's no
@@ -1102,7 +1142,8 @@ void SessionTab::requestConnectOptions(
}
void SessionTab::showPasswordPrompt(const QString& labelText,
std::function<void(std::optional<QString>)> callback)
std::function<void(std::optional<QString>)> callback,
bool maskInput)
{
if (m_passwordPromptCallback) {
const auto previousCallback = m_passwordPromptCallback;
@@ -1113,6 +1154,7 @@ void SessionTab::showPasswordPrompt(const QString& labelText,
m_passwordPromptCallback = std::move(callback);
m_passwordPromptLabel->setText(labelText);
m_passwordPromptInput->clear();
m_passwordPromptInput->setEchoMode(maskInput ? QLineEdit::Password : QLineEdit::Normal);
m_passwordPromptBar->setVisible(true);
m_passwordPromptInput->setFocus();
}