/** * Decrypts a text using cipher text and cipher key * Chooses between a permanent or a individual password using the preferences */ void MainWindow::on_actionDecrypt_triggered() { if (passwordUsed) { query.prepare("SELECT `Password` FROM `password`;"); query.exec(); QString passwordBase; while ( query.next() ) { passwordBase = query.value(0).toString(); } QByteArray passwordTemp = QByteArray::fromBase64( passwordBase.toUtf8() ); password = QString(passwordTemp); Regex regex; QRegExp rePassword( regex.getPassword() ); if ( !password.isEmpty() && password.contains(rePassword) ) { decrypted = decrypt(password); ui->textEdit_mainWindow_surface->setHtml( QString(decrypted) ); } else { QMessageBox::critical(this, tr("Error"), tr("An error has ocurred. Please revise your entries and note the following:\n" "A Password must contain at least one upper case letter.\n" "A Password must contain at least one lower case letter.\n" "A Password must contain at least one numeric digit.")); qDebug() << "Data could not be decrypted because the password requirements were not met."; } } else { bool ok = false; QInputDialog* inputDialog = new QInputDialog(); inputDialog->setAttribute(Qt::WA_DeleteOnClose, true); inputDialog->setOptions(QInputDialog::NoButtons); password = inputDialog->getText(NULL ,tr("Decryption"), tr("Password:"******"", &ok); if (ok) { Regex regex; QRegExp rePassword( regex.getPassword() ); if ( !password.isEmpty() && password.contains(rePassword) ) { decrypted = decrypt(password); ui->textEdit_mainWindow_surface->setHtml( QString(decrypted) ); } else { QMessageBox::critical(this, tr("Error"), tr("An error has ocurred. Please revise your entries and note the following:\n" "A Password must contain at least one upper case letter.\n" "A Password must contain at least one lower case letter.\n" "A Password must contain at least one numeric digit.")); qDebug() << "Data could not be decrypted because the password requirements were not met."; } } else { inputDialog->reject(); } inputDialog->close(); } }