1 #include "PasswordDialog.h"
6 #include <QCryptographicHash>
10 PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText, const QString &aTitle, QWidget *aParent ) :
13 setWindowTitle( aTitle.isNull() ? tr( "Enter password" ) : aTitle );
16 iPasswordHash = aPassword.toUtf8();
20 .--------title---------.
23 | [***_______________] |
25 '----------------------'
28 QVBoxLayout *layout = new QVBoxLayout;
30 if ( !aText.isNull() )
32 QLabel *text = new QLabel( aText );
33 layout->addWidget( text );
37 iPasswordEdit = new QLineEdit;
38 iPasswordEdit->setEchoMode( QLineEdit::Password );
39 layout->addWidget( iPasswordEdit );
41 QHBoxLayout *buttonLayout = new QHBoxLayout;
42 QPushButton *buttonOK = new QPushButton( tr( "OK" ) );
43 QPushButton *buttonCancel = new QPushButton( tr( "Cancel" ) );
45 buttonLayout->addStretch();
46 buttonLayout->addWidget( buttonOK );
47 buttonLayout->addWidget( buttonCancel );
48 buttonLayout->addStretch();
49 layout->addSpacing( 5 );
50 layout->addLayout( buttonLayout );
52 // Connect the buttons pressed signals to corresponding slots
53 connect( buttonOK, SIGNAL( pressed() ), this, SLOT( okButtonPressed() ) );
54 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( cancelButtonPressed() ) );
60 PasswordDialog::~PasswordDialog()
64 void PasswordDialog::okButtonPressed()
66 qDebug() << "PasswordDialog::okButtonPressed()";
68 // Get md5 hash from the password entered to the dialog
69 QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
70 hash->addData( iPasswordEdit->text().toUtf8() );
71 QByteArray userpw = hash->result();
76 // Compare the password hashes and emit corresponding signal tellin if the password was correct
77 if ( iPasswordHash == userpw.toHex() )
79 emit passwordEntered( PasswordDialog::Correct );
80 qDebug() << "Password OK";
84 emit passwordEntered( PasswordDialog::Incorrect );
85 qDebug() << "Incorrect password!";
89 void PasswordDialog::cancelButtonPressed()
91 qDebug() << "PasswordDialog::cancelButtonPressed()";
94 emit passwordEntered( PasswordDialog::Canceled );