summaryrefslogtreecommitdiffstats
path: root/pica-client/askpassword.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pica-client/askpassword.cpp')
-rw-r--r--pica-client/askpassword.cpp73
1 files changed, 58 insertions, 15 deletions
diff --git a/pica-client/askpassword.cpp b/pica-client/askpassword.cpp
index a171217..70f8644 100644
--- a/pica-client/askpassword.cpp
+++ b/pica-client/askpassword.cpp
@@ -2,38 +2,54 @@
#include "globals.h"
#include <string.h>
#include <QInputDialog>
+#include <QThread>
#include "accounts.h"
QMutex AskPassword::passwd_mutex;
-QMap<QByteArray,QString> AskPassword::idpasswd;
+char AskPassword::current_password[256];
+int AskPassword::is_invalid = 0;
+int AskPassword::is_cancelled = 0;
+int AskPassword::is_set = 0;
AskPassword::AskPassword(QObject *parent) :
QObject(parent)
{
- connect(this,SIGNAL(password_requested()),this,SLOT(password_dialog()),Qt::BlockingQueuedConnection);
+ connect(this,SIGNAL(password_requested()),this,SLOT(password_dialog()), Qt::BlockingQueuedConnection);
+}
+
+AskPassword::~AskPassword()
+{
+ memset(current_password, 0, sizeof(current_password));
}
int AskPassword::ask_password_cb(char *buf, int size, int rwflag, void *userdata)
{
- QString pswd;
- QByteArray id = QByteArray((const char*) userdata, PICA_ID_SIZE);
+ //QString pswd;
+ //QByteArray id = QByteArray((const char*) userdata, PICA_ID_SIZE);
+
+ if (is_cancelled)
+ return 0;
passwd_mutex.lock();
- if (idpasswd.contains(id))
+ if (!is_set || is_invalid)
{
- pswd = idpasswd[id];
+ if (askpassword->thread() != QThread::currentThread())
+ askpassword->emit_sig();
+ else
+ askpassword->password_dialog();
}
- else
+
+ if (is_set)
{
- askpassword->emit_sig();
- pswd = idpasswd[id];
+ strncpy(buf, current_password, size);
+ buf[size - 1] = 0;
}
+
passwd_mutex.unlock();
- strncpy(buf, pswd.toUtf8().constData(), size);
- buf[size - 1] = 0;
- return(strlen(buf));
+
+ return is_set ? (strlen(buf)) : 0;
}
void AskPassword::emit_sig()
@@ -41,15 +57,42 @@ void AskPassword::emit_sig()
emit password_requested();
}
+void AskPassword::clear()
+{
+ passwd_mutex.lock();
+ is_invalid = 0;
+ is_set = 0;
+ is_cancelled = 0;
+ memset(current_password, 0, sizeof(current_password));
+ passwd_mutex.unlock();
+
+}
+
+void AskPassword::setInvalidPassword()
+{
+ passwd_mutex.lock();
+ is_invalid = 1;
+ memset(current_password, 0, sizeof(current_password));
+ passwd_mutex.unlock();
+}
+
void AskPassword::password_dialog()
{
- bool ok;
- QString title = QObject::tr("Enter private key passphrase");
+ bool ok = false;
+ QString title = is_invalid ? QObject::tr("Invalid passphrase, try again") : QObject::tr("Enter private key passphrase");
QString text = QObject::tr(QString("Passphrase for account %1 \n (%2)")
.arg(Accounts::GetCurrentAccount().name)
.arg(Accounts::GetCurrentAccount().id.toBase64().constData()).toUtf8().constData());
QString psw = QInputDialog::getText((QWidget*)mainwindow,title,text,QLineEdit::Password,QString(),&ok);
+
if (ok)
- idpasswd[Accounts::GetCurrentAccount().id] = psw;
+ {
+ strncpy(current_password, psw.toUtf8().constData(), sizeof(current_password));
+ current_password[sizeof(current_password) - 1] = 0;
+ is_set = 1;
+ is_invalid = 0;
+ }
+ else
+ is_cancelled = 1;
}