3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
6 Permission to use, copy, modify, and distribute this software
7 and its documentation for any purpose and without fee is hereby
8 granted, provided that the above copyright notice appear in all
9 copies and that both that the copyright notice and this
10 permission notice and warranty disclaimer appear in supporting
11 documentation, and that the name of the author not be used in
12 advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 The author disclaim all warranties with regard to this
16 software, including all implied warranties of merchantability
17 and fitness. In no event shall the author be liable for any
18 special, indirect or consequential damages or any damages
19 whatsoever resulting from loss of use, data or profits, whether
20 in an action of contract, negligence or other tortious action,
21 arising out of or in connection with the use or performance of
25 #include "passwddlg.h"
29 #include <kmessagebox.h>
31 KDEpasswd1Dialog::KDEpasswd1Dialog()
34 setCaption(i18n("Change Password"));
35 setPrompt(i18n("Please enter your current password:"));
39 KDEpasswd1Dialog::~KDEpasswd1Dialog()
43 void KDEpasswd1Dialog::accept()
45 PasswdProcess
proc(0);
47 int ret
= proc
.checkCurrent(password().toLocal8Bit());
52 QString msg
= QString::fromLocal8Bit(proc
.error());
54 msg
= "<p>\"<i>" + msg
+ "</i>\"";
55 msg
= "<qt>" + i18n("Conversation with 'passwd' failed.") + msg
;
56 KMessageBox::error(this, msg
);
62 return KPasswordDialog::accept();
64 case PasswdProcess::PasswdNotFound
:
65 KMessageBox::error(this, i18n("Could not find the program 'passwd'."));
69 case PasswdProcess::PasswordIncorrect
:
70 KMessageBox::sorry(this, i18n("Incorrect password. Please try again."));
74 KMessageBox::error(this, i18n("Internal error: illegal return value "
75 "from PasswdProcess::checkCurrent."));
83 int KDEpasswd1Dialog::getPassword(QByteArray
&password
)
85 KDEpasswd1Dialog
*dlg
= new KDEpasswd1Dialog();
86 int res
= dlg
->exec();
88 password
= dlg
->password().toLocal8Bit();
95 KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass
, const QByteArray
&user
)
96 : KNewPasswordDialog()
101 setCaption(i18n("Change Password"));
102 if (m_User
.isEmpty())
103 setPrompt(i18n("Please enter your new password:"));
105 setPrompt(i18n("Please enter the new password for user <b>%1</b>:", QString::fromLocal8Bit(m_User
)));
109 KDEpasswd2Dialog::~KDEpasswd2Dialog()
114 void KDEpasswd2Dialog::accept()
116 PasswdProcess
proc(m_User
);
118 QString p
=password();
122 switch(KMessageBox::warningYesNoCancel(this,
124 i18n("Your password is longer than 8 characters. On some "
125 "systems, this can cause problems. You can truncate "
126 "the password to 8 characters, or leave it as it is.") :
127 i18n("The password is longer than 8 characters. On some "
128 "systems, this can cause problems. You can truncate "
129 "the password to 8 characters, or leave it as it is.")
131 i18n("Password Too Long"),
132 KGuiItem(i18n("Truncate")),
133 KGuiItem(i18n("Use as Is")),
134 KStandardGuiItem::cancel(),
137 case KMessageBox::Yes
:
140 case KMessageBox::No
:
146 int ret
= proc
.exec(m_Pass
, p
.toLocal8Bit());
152 QString msg
= QString::fromLocal8Bit(proc
.error());
154 msg
= "<p>\"<i>" + msg
+ "</i>\"";
155 msg
= "<qt>" + i18n("Your password has been changed.") + msg
;
156 KMessageBox::information(0L, msg
);
157 return KNewPasswordDialog::accept();
160 case PasswdProcess::PasswordNotGood
:
162 QString msg
= QString::fromLocal8Bit(proc
.error());
164 msg
= "<p>\"<i>" + msg
+ "</i>\"";
165 msg
= "<qt>" + i18n("Your password has not been changed.") + msg
;
167 // The pw change did not succeed. Print the error.
168 KMessageBox::sorry(this, msg
);
173 QString msg
= QString::fromLocal8Bit(proc
.error());
175 msg
= "<p>\"<i>" + msg
+ "</i>\"";
176 msg
= "<qt>" + i18n("Conversation with 'passwd' failed.") + msg
;
177 KMessageBox::sorry(this, msg
);
182 return KNewPasswordDialog::accept();
187 #include "passwddlg.moc"