diff options
Diffstat (limited to 'pica-client/askpassword.cpp')
| -rw-r--r-- | pica-client/askpassword.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/pica-client/askpassword.cpp b/pica-client/askpassword.cpp index 70f8644..cf21ed4 100644 --- a/pica-client/askpassword.cpp +++ b/pica-client/askpassword.cpp @@ -12,87 +12,87 @@ int AskPassword::is_cancelled = 0; int AskPassword::is_set = 0; AskPassword::AskPassword(QObject *parent) : - 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)); + 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; + if (is_cancelled) + return 0; - passwd_mutex.lock(); + passwd_mutex.lock(); - if (!is_set || is_invalid) - { - if (askpassword->thread() != QThread::currentThread()) - askpassword->emit_sig(); - else - askpassword->password_dialog(); - } + if (!is_set || is_invalid) + { + if (askpassword->thread() != QThread::currentThread()) + askpassword->emit_sig(); + else + askpassword->password_dialog(); + } - if (is_set) - { - strncpy(buf, current_password, size); - buf[size - 1] = 0; - } + if (is_set) + { + strncpy(buf, current_password, size); + buf[size - 1] = 0; + } - passwd_mutex.unlock(); + passwd_mutex.unlock(); - return is_set ? (strlen(buf)) : 0; + return is_set ? (strlen(buf)) : 0; } void AskPassword::emit_sig() { - emit password_requested(); + 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(); + 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(); + passwd_mutex.lock(); + is_invalid = 1; + memset(current_password, 0, sizeof(current_password)); + passwd_mutex.unlock(); } void AskPassword::password_dialog() { - 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) - { - 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; + 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) + { + 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; } |
