diff --git a/kdepasswd/kcm/main.cpp b/kdepasswd/kcm/main.cpp index f51c16f16c..77f3ff92ac 100644 --- a/kdepasswd/kcm/main.cpp +++ b/kdepasswd/kcm/main.cpp @@ -214,11 +214,9 @@ void KCMUserAccount::save() /* Save realname to /etc/passwd */ if ( _mw->leRealname->isModified() ) { - QByteArray password; - int ret = KPasswordDialog::getPassword( _mw, password, i18n("Please enter " - "your password in order to save your settings:")); - - if ( !ret ) + KPasswordDialog dlg( _mw ); + dlg.setPrompt(i18n("Please enter your password in order to save your settings:")); + if ( !dlg.exec() ) { KMessageBox::sorry( this, i18n("You must enter " "your password in order to change your information.")); @@ -226,7 +224,7 @@ void KCMUserAccount::save() } ChfnProcess *proc = new ChfnProcess(); - ret = proc->exec(password, _mw->leRealname->text().toAscii() ); + int ret = proc->exec(dlg.password().toAscii() , _mw->leRealname->text().toAscii() ); if ( ret ) { if ( ret == ChfnProcess::PasswordError ) diff --git a/kdepasswd/passwddlg.cpp b/kdepasswd/passwddlg.cpp index 3401d5d9e3..915365cb75 100644 --- a/kdepasswd/passwddlg.cpp +++ b/kdepasswd/passwddlg.cpp @@ -13,7 +13,7 @@ #include "passwddlg.h" KDEpasswd1Dialog::KDEpasswd1Dialog() - : KPasswordDialog(Password, false, 0) + : KPasswordDialog() { setCaption(i18n("Change Password")); setPrompt(i18n("Please enter your current password:")); @@ -24,12 +24,11 @@ KDEpasswd1Dialog::~KDEpasswd1Dialog() { } - -bool KDEpasswd1Dialog::checkPassword(const char *password) +void KDEpasswd1Dialog::accept() { PasswdProcess proc(0); - int ret = proc.checkCurrent(password); + int ret = proc.checkCurrent(password().toLocal8Bit()); switch (ret) { case -1: @@ -40,26 +39,26 @@ bool KDEpasswd1Dialog::checkPassword(const char *password) msg = "" + i18n("Conversation with 'passwd' failed.") + msg; KMessageBox::error(this, msg); done(Rejected); - return false; + return; } case 0: - return true; + return KPasswordDialog::accept(); case PasswdProcess::PasswdNotFound: KMessageBox::error(this, i18n("Could not find the program 'passwd'.")); done(Rejected); - return false; + return; case PasswdProcess::PasswordIncorrect: KMessageBox::sorry(this, i18n("Incorrect password. Please try again.")); - return false; + return; default: KMessageBox::error(this, i18n("Internal error: illegal return value " "from PasswdProcess::checkCurrent.")); done(Rejected); - return false; + return; } } @@ -78,7 +77,7 @@ int KDEpasswd1Dialog::getPassword(QByteArray &password) KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass, QByteArray user) - : KPasswordDialog(NewPassword, false, 0) + : KNewPasswordDialog() { m_Pass = oldpass; m_User = user; @@ -96,11 +95,13 @@ KDEpasswd2Dialog::~KDEpasswd2Dialog() } -bool KDEpasswd2Dialog::checkPassword(const char *password) +void KDEpasswd2Dialog::accept() { PasswdProcess proc(m_User); + + QString p=password(); - if (strlen(password) > 8) + if (p.length() > 8) { switch(KMessageBox::warningYesNoCancel(this, m_User.isEmpty() ? @@ -117,15 +118,15 @@ bool KDEpasswd2Dialog::checkPassword(const char *password) "truncatePassword")) { case KMessageBox::Yes : - const_cast(password)[8] = '\000'; + p=p.left(8); break; case KMessageBox::No : break; - default : return false; + default : return; } } - int ret = proc.exec(m_Pass, password); + int ret = proc.exec(m_Pass, p.toLocal8Bit()); switch (ret) { case 0: @@ -136,7 +137,7 @@ bool KDEpasswd2Dialog::checkPassword(const char *password) msg = "

\"" + msg + "\""; msg = "" + i18n("Your password has been changed.") + msg; KMessageBox::information(0L, msg); - return true; + return KNewPasswordDialog::accept(); } case PasswdProcess::PasswordNotGood: @@ -148,7 +149,7 @@ bool KDEpasswd2Dialog::checkPassword(const char *password) // The pw change did not succeed. Print the error. KMessageBox::sorry(this, msg); - return false; + return; } default: @@ -158,10 +159,11 @@ bool KDEpasswd2Dialog::checkPassword(const char *password) msg = "" + i18n("Conversation with 'passwd' failed.") + msg; KMessageBox::sorry(this, msg); done(Rejected); - return true; + return; } - return true; + return KNewPasswordDialog::accept(); + } diff --git a/kdepasswd/passwddlg.h b/kdepasswd/passwddlg.h index c33b9a3c1f..22b56f13a6 100644 --- a/kdepasswd/passwddlg.h +++ b/kdepasswd/passwddlg.h @@ -10,6 +10,7 @@ #define __PasswdDlg_h_Incluced__ #include +#include #include class KDEpasswd1Dialog @@ -23,13 +24,12 @@ public: static int getPassword(QByteArray &password); -protected: - bool checkPassword(const char *password); + void accept(); }; class KDEpasswd2Dialog - : public KPasswordDialog + : public KNewPasswordDialog { Q_OBJECT @@ -37,6 +37,9 @@ public: KDEpasswd2Dialog(const char *oldpass, QByteArray user); ~KDEpasswd2Dialog(); + void accept(); + + protected: bool checkPassword(const char *password); diff --git a/kdialog/widgets.cpp b/kdialog/widgets.cpp index 3694ffd859..205f43b668 100644 --- a/kdialog/widgets.cpp +++ b/kdialog/widgets.cpp @@ -74,8 +74,7 @@ bool Widgets::inputBox(QWidget *parent, const QString& title, const QString& tex bool Widgets::passwordBox(QWidget *parent, const QString& title, const QString& text, QString &result) { - KPasswordDialog dlg( KPasswordDialog::Password, false, 0, parent ); - + KPasswordDialog dlg( parent ); kapp->setTopWidget( &dlg ); dlg.setCaption(title); dlg.setPrompt(text);