void SshKeyGenerator::generatePkcs8KeyString(const KeyPtr &key, bool privateKey, Botan::RandomNumberGenerator &rng) { Pipe pipe; pipe.start_msg(); QByteArray *keyData; if (privateKey) { QInputDialog d; d.setInputMode(QInputDialog::TextInput); d.setTextEchoMode(QLineEdit::Password); d.setWindowTitle(tr("Password for Private Key")); d.setLabelText(tr("It is recommended that you secure your private key\n" "with a password, which you can can enter below.")); d.setOkButtonText(tr("Encrypt key file")); d.setCancelButtonText(tr("Do not encrypt key file")); int result = QDialog::Accepted; QString password; while (result == QDialog::Accepted && password.isEmpty()) { result = d.exec(); password = d.textValue(); } if (result == QDialog::Accepted) PKCS8::encrypt_key(*key, pipe, rng, password.toLocal8Bit().data()); else PKCS8::encode(*key, pipe); keyData = &m_privateKey; } else { X509::encode(*key, pipe); keyData = &m_publicKey; } pipe.end_msg(); keyData->resize(pipe.remaining(pipe.message_count() - 1)); pipe.read(convertByteArray(*keyData), keyData->size(), pipe.message_count() - 1); }
QString GUI::_passwordDialog(const QString& cancel, const QString& body) { // we use a hack. It is considered that closing the dialog without explicitly clicking // disable history is confusing. But we can't distinguish between clicking the cancel // button and closing the dialog. So instead, we reverse the Ok and Cancel roles, // so that nothing but explicitly clicking disable history closes the dialog QString ret; QInputDialog dialog; dialog.setWindowTitle(tr("Enter your password")); dialog.setOkButtonText(cancel); dialog.setCancelButtonText(tr("Decrypt")); dialog.setInputMode(QInputDialog::TextInput); dialog.setTextEchoMode(QLineEdit::Password); dialog.setLabelText(body); // problem with previous hack: the default button is disable history, not decrypt. // use another hack to reverse the default buttons. // http://www.qtcentre.org/threads/49924-Change-property-of-QInputDialog-button QList<QDialogButtonBox*> l = dialog.findChildren<QDialogButtonBox*>(); if (!l.isEmpty()) { QPushButton* ok = l.first()->button(QDialogButtonBox::Ok); QPushButton* cancel = l.first()->button(QDialogButtonBox::Cancel); if (ok && cancel) { ok->setAutoDefault(false); ok->setDefault(false); ok->setText(QApplication::tr("Ok")); cancel->setAutoDefault(true); cancel->setDefault(true); cancel->setText(QApplication::tr("Cancel")); } else { qWarning() << "PasswordDialog: Missing button!"; } } else { qWarning() << "PasswordDialog: No QDialogButtonBox!"; } // using similar code, set QLabels to wrap for (auto* label : dialog.findChildren<QLabel*>()) label->setWordWrap(true); while (true) { int val = dialog.exec(); if (val == QDialog::Accepted) return QString(); ret = dialog.textValue(); if (!ret.isEmpty()) return ret; dialog.setTextValue(""); dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:")); } }
bool NotifyQt::askForPassword(const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled) { RsAutoUpdatePage::lockAllEvents() ; QInputDialog dialog; dialog.setWindowTitle(tr("PGP key passphrase")); dialog.setLabelText((prev_is_bad ? QString("%1\n\n").arg(tr("Wrong password !")) : QString()) + QString("%1:\n %2").arg(tr("Please enter your PGP password for key"), QString::fromUtf8(key_details.c_str()))); dialog.setTextEchoMode(QLineEdit::Password); dialog.setModal(true); int ret = dialog.exec(); cancelled = false ; RsAutoUpdatePage::unlockAllEvents() ; if (ret == QDialog::Rejected) { password.clear() ; cancelled = true ; return true ; } if (ret == QDialog::Accepted) { password = dialog.textValue().toUtf8().constData(); return true; } return false; }
QString SshKeyGenerator::getPassword() const { QInputDialog d; d.setInputMode(QInputDialog::TextInput); d.setTextEchoMode(QLineEdit::Password); d.setWindowTitle(tr("Password for Private Key")); d.setLabelText(tr("It is recommended that you secure your private key\n" "with a password, which you can enter below.")); d.setOkButtonText(tr("Encrypt key file")); d.setCancelButtonText(tr("Do not encrypt key file")); int result = QDialog::Accepted; QString password; while (result == QDialog::Accepted && password.isEmpty()) { result = d.exec(); password = d.textValue(); } return result == QDialog::Accepted ? password : QString(); }
std::string NotifyQt::askForPassword(const std::string& key_details,bool prev_is_bad) { RsAutoUpdatePage::lockAllEvents() ; QInputDialog dialog; dialog.setWindowTitle(tr("GPG key passphrase")); dialog.setLabelText((prev_is_bad?tr("Wrong password !") + "\n\n" : QString()) + tr("Please enter the password to unlock the following GPG key:") + "\n" + QString::fromStdString(key_details)); dialog.setTextEchoMode(QLineEdit::Password); dialog.setWindowIcon(QIcon(":/images/rstray3.png")); int ret = dialog.exec(); RsAutoUpdatePage::unlockAllEvents() ; if (ret) { return dialog.textValue().toStdString(); } return ""; }
void HttpCredentialsGui::showDialog() { QString msg = tr("Please enter %1 password:<br>" "<br>" "User: %2<br>" "Account: %3<br>") .arg(Utility::escape(Theme::instance()->appNameGUI()), Utility::escape(_user), Utility::escape(_account->displayName())); QString reqTxt = requestAppPasswordText(_account); if (!reqTxt.isEmpty()) { msg += QLatin1String("<br>") + reqTxt + QLatin1String("<br>"); } if (!_fetchErrorString.isEmpty()) { msg += QLatin1String("<br>") + tr("Reading from keychain failed with error: '%1'") .arg(Utility::escape(_fetchErrorString)) + QLatin1String("<br>"); } QInputDialog dialog; dialog.setWindowTitle(tr("Enter Password")); dialog.setLabelText(msg); dialog.setTextValue(_previousPassword); dialog.setTextEchoMode(QLineEdit::Password); if (QLabel *dialogLabel = dialog.findChild<QLabel *>()) { dialogLabel->setOpenExternalLinks(true); dialogLabel->setTextFormat(Qt::RichText); } bool ok = dialog.exec(); if (ok) { _password = dialog.textValue(); _refreshToken.clear(); _ready = true; persist(); } emit asked(); }
bool NotifyQt::askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password,bool& cancelled) { RsAutoUpdatePage::lockAllEvents() ; QInputDialog dialog; if (title == "") { dialog.setWindowTitle(tr("PGP key passphrase")); } else if (title == "AuthSSLimpl::SignX509ReqWithGPG()") { dialog.setWindowTitle(tr("You need to sign your node's certificate.")); } else if (title == "p3IdService::service_CreateGroup()") { dialog.setWindowTitle(tr("You need to sign your forum/chatrooms identity.")); } else { dialog.setWindowTitle(QString::fromStdString(title)); } dialog.setLabelText((prev_is_bad ? QString("%1\n\n").arg(tr("Wrong password !")) : QString()) + QString("%1:\n %2").arg(tr("Please enter your PGP password for key"), QString::fromUtf8(key_details.c_str()))); dialog.setTextEchoMode(QLineEdit::Password); dialog.setModal(true); int ret = dialog.exec(); cancelled = false ; RsAutoUpdatePage::unlockAllEvents() ; if (ret == QDialog::Rejected) { password.clear() ; cancelled = true ; return true ; } if (ret == QDialog::Accepted) { password = dialog.textValue().toUtf8().constData(); return true; } return false; }
int FileListModel::importFromCsv(QWidget *parent, const QString &inFile) { QFile file(inFile); if(!file.open(QIODevice::ReadOnly)) { return CsvError_FileOpen; } QTextCodec *codec = NULL; QByteArray bomCheck = file.peek(16); if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xef\xbb\xbf")) { codec = QTextCodec::codecForName("UTF-8"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xff\xfe")) { codec = QTextCodec::codecForName("UTF-16LE"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xfe\xff")) { codec = QTextCodec::codecForName("UTF-16BE"); } else { const QString systemDefault = tr("(System Default)"); QStringList codecList; codecList.append(systemDefault); codecList.append(lamexp_available_codepages()); QInputDialog *input = new QInputDialog(parent); input->setLabelText(EXPAND(tr("Select ANSI Codepage for CSV file:"))); input->setOkButtonText(tr("OK")); input->setCancelButtonText(tr("Cancel")); input->setTextEchoMode(QLineEdit::Normal); input->setComboBoxItems(codecList); if(input->exec() < 1) { LAMEXP_DELETE(input); return CsvError_Aborted; } if(input->textValue().compare(systemDefault, Qt::CaseInsensitive)) { qDebug("User-selected codec is: %s", input->textValue().toLatin1().constData()); codec = QTextCodec::codecForName(input->textValue().toLatin1().constData()); } else { qDebug("Going to use the system's default codec!"); codec = QTextCodec::codecForName("System"); } LAMEXP_DELETE(input); } bomCheck.clear(); //----------------------// QTextStream stream(&file); stream.setAutoDetectUnicode(false); stream.setCodec(codec); QString headerLine = stream.readLine().simplified(); while(headerLine.isEmpty()) { if(stream.atEnd()) { qWarning("The file appears to be empty!"); return CsvError_FileRead; } qWarning("Skipping a blank line at beginning of CSV file!"); headerLine = stream.readLine().simplified(); } QStringList header = headerLine.split(";", QString::KeepEmptyParts); const int nCols = header.count(); const int nFiles = m_fileList.count(); if(nCols < 1) { qWarning("Header appears to be empty!"); return CsvError_FileRead; } bool *ignore = new bool[nCols]; memset(ignore, 0, sizeof(bool) * nCols); for(int i = 0; i < nCols; i++) { if((header[i] = header[i].trimmed()).isEmpty()) { ignore[i] = true; } } //----------------------// for(int i = 0; i < nFiles; i++) { if(stream.atEnd()) { LAMEXP_DELETE_ARRAY(ignore); return CsvError_Incomplete; } QString line = stream.readLine().simplified(); if(line.isEmpty()) { qWarning("Skipping a blank line in CSV file!"); continue; } QStringList data = line.split(";", QString::KeepEmptyParts); if(data.count() < header.count()) { qWarning("Skipping an incomplete line in CSV file!"); continue; } const QString key = m_fileList[i]; for(int j = 0; j < nCols; j++) { if(ignore[j]) { continue; } else if(CHECK_HDR(header.at(j), "POSITION")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setPosition(temp); } else if(CHECK_HDR(header.at(j), "TITLE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setTitle(temp); } else if(CHECK_HDR(header.at(j), "ARTIST")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setArtist(temp); } else if(CHECK_HDR(header.at(j), "ALBUM")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setAlbum(temp); } else if(CHECK_HDR(header.at(j), "GENRE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setGenre(temp); } else if(CHECK_HDR(header.at(j), "YEAR")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setYear(temp); } else if(CHECK_HDR(header.at(j), "COMMENT")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setComment(temp); } else { qWarning("Unkonw field '%s' will be ignored!", QUTF8(header.at(j))); ignore[j] = true; if(!checkArray(ignore, false, nCols)) { qWarning("No known fields left, aborting!"); return CsvError_NoTags; } } } } //----------------------// LAMEXP_DELETE_ARRAY(ignore); return CsvError_OK; }