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 // Store the password hash to iPasswordHash
17 // ( aPassword should be allready encoded )
18 // QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
19 // hash->addData( aPassword.toUtf8() );
20 // iPasswordHash = hash->result();
22 iPasswordHash = aPassword.toUtf8();
26 .--------title---------.
29 | [***_______________] |
31 '----------------------'
34 QVBoxLayout *layout = new QVBoxLayout;
36 if ( !aText.isNull() )
38 QLabel *text = new QLabel( aText );
39 layout->addWidget( text );
43 iPasswordEdit = new QLineEdit;
44 iPasswordEdit->setEchoMode( QLineEdit::Password );
45 layout->addWidget( iPasswordEdit );
47 QHBoxLayout *buttonLayout = new QHBoxLayout;
48 QPushButton *buttonOK = new QPushButton( tr( "OK" ) );
49 QPushButton *buttonCancel = new QPushButton( tr( "Cancel" ) );
51 buttonLayout->addStretch();
52 buttonLayout->addWidget( buttonOK );
53 buttonLayout->addWidget( buttonCancel );
54 buttonLayout->addStretch();
55 layout->addSpacing( 5 );
56 layout->addLayout( buttonLayout );
58 // Connect the buttons pressed signals to corresponding slots
59 connect( buttonOK, SIGNAL( pressed() ), this, SLOT( okButtonPressed() ) );
60 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( cancelButtonPressed() ) );
68 PasswordDialog::~PasswordDialog()
73 void PasswordDialog::okButtonPressed()
75 qDebug() << "PasswordDialog::okButtonPressed()";
77 // Get md5 hash from the password entered to the dialog
78 QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
79 hash->addData( iPasswordEdit->text().toUtf8() );
80 QByteArray userpw = hash->result();
85 // Compare the password hashes and emit corresponding signal tellin if the password was correct
86 if ( iPasswordHash == userpw.toHex() )
88 emit passwordEntered( PasswordDialog::Correct );
89 qDebug() << "Password OK";
93 emit passwordEntered( PasswordDialog::Incorrect );
94 qDebug() << "Incorrect password!";
98 void PasswordDialog::cancelButtonPressed()
100 qDebug() << "PasswordDialog::cancelButtonPressed()";
103 emit passwordEntered( PasswordDialog::Canceled );