1 #include "PasswordDialog.h"
7 #include <QCryptographicHash>
11 PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText, const QString &aTitle, QWidget *aParent ) :
14 setWindowTitle( aTitle.isNull() ? tr( "Enter password" ) : aTitle );
17 iPasswordHash = aPassword.toUtf8();
21 .--------title---------.
24 | [***_______________] |
26 '----------------------'
29 QVBoxLayout *layout = new QVBoxLayout;
31 if ( !aText.isNull() )
33 QLabel *text = new QLabel( aText );
34 layout->addWidget( text );
38 iPasswordEdit = new QLineEdit;
39 iPasswordEdit->setEchoMode( QLineEdit::Password );
40 layout->addWidget( iPasswordEdit );
42 QHBoxLayout *buttonLayout = new QHBoxLayout;
43 QPushButton *buttonOK = new QPushButton( tr( "OK" ) );
44 QPushButton *buttonCancel = new QPushButton( tr( "Cancel" ) );
46 buttonLayout->addStretch();
47 buttonLayout->addWidget( buttonOK );
48 buttonLayout->addWidget( buttonCancel );
49 buttonLayout->addStretch();
50 layout->addSpacing( 5 );
51 layout->addLayout( buttonLayout );
53 // Connect the user action signals to corresponding slots
54 connect( buttonOK, SIGNAL( pressed() ), this, SLOT( okButtonPressed() ) );
55 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( cancelButtonPressed() ) );
61 PasswordDialog::~PasswordDialog()
65 void PasswordDialog::okButtonPressed()
67 qDebug() << "PasswordDialog::okButtonPressed()";
69 // Get md5 hash from the password entered to the dialog
70 QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
71 hash->addData( iPasswordEdit->text().toUtf8() );
72 QByteArray userpw = hash->result();
77 // Compare the password hashes and emit corresponding signal tellin if the password was correct
78 if ( iPasswordHash == userpw.toHex() )
80 emit passwordEntered( PasswordDialog::Correct );
81 qDebug() << "Password OK";
85 emit passwordEntered( PasswordDialog::Incorrect );
86 qDebug() << "Incorrect password!";
90 void PasswordDialog::cancelButtonPressed()
92 qDebug() << "PasswordDialog::cancelButtonPressed()";
95 emit passwordEntered( PasswordDialog::Canceled );