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 iText = new QLabel( aText );
32 layout->addWidget( iText );
35 iPasswordEdit = new QLineEdit;
36 iPasswordEdit->setEchoMode( QLineEdit::Password );
37 layout->addWidget( iPasswordEdit );
39 QHBoxLayout *buttonLayout = new QHBoxLayout;
40 QPushButton *buttonOK = new QPushButton( tr( "OK" ) );
41 QPushButton *buttonCancel = new QPushButton( tr( "Cancel" ) );
43 buttonLayout->addStretch();
44 buttonLayout->addWidget( buttonOK );
45 buttonLayout->addWidget( buttonCancel );
46 buttonLayout->addStretch();
47 layout->addSpacing( 5 );
48 layout->addLayout( buttonLayout );
50 // Connect the user action signals to corresponding slots
51 connect( buttonOK, SIGNAL( released() ), this, SLOT( okButtonPressed() ) );
52 connect( buttonCancel, SIGNAL( released() ), this, SLOT( cancelButtonPressed() ) );
58 PasswordDialog::~PasswordDialog()
62 void PasswordDialog::okButtonPressed()
64 qDebug() << "PasswordDialog::okButtonPressed()";
66 // Get md5 hash from the password entered to the dialog
67 QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
68 hash->addData( iPasswordEdit->text().toUtf8() );
69 QByteArray userpw = hash->result();
74 // Compare the password hashes and emit corresponding signal tellin if the password was correct
75 if ( iPasswordHash == userpw.toHex() )
77 emit passwordEntered( PasswordDialog::Correct );
78 qDebug() << "Password OK";
82 emit passwordEntered( PasswordDialog::Incorrect );
83 qDebug() << "Incorrect password!";
87 void PasswordDialog::cancelButtonPressed()
89 qDebug() << "PasswordDialog::cancelButtonPressed()";
92 emit passwordEntered( PasswordDialog::Canceled );
95 void PasswordDialog::update( const QString &aText )
97 qDebug() << "PasswordDialog::update()";
98 iText->setText( aText );