summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/securityplugins/pin/pin.cpp22
-rw-r--r--noncore/securityplugins/pin/pin.h3
2 files changed, 19 insertions, 6 deletions
diff --git a/noncore/securityplugins/pin/pin.cpp b/noncore/securityplugins/pin/pin.cpp
index c21ffcd..2accb9c 100644
--- a/noncore/securityplugins/pin/pin.cpp
+++ b/noncore/securityplugins/pin/pin.cpp
@@ -1,90 +1,89 @@
/**
* \note Taken from opie-security and libqpe password.cpp, and modified for Opie multiauth by Clement Seveillac
*/
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "pin.h"
#include "pinDialogBase.h"
-#include "pinConfigWidget.h"
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/oapplication.h>
/* QT */
#include <qpe/config.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qtextview.h>
#include <qstring.h>
#include <qdialog.h>
/* UNIX */
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
extern "C" char *crypt(const char *key, const char *salt);
using Opie::Security::MultiauthConfigWidget;
using Opie::Security::MultiauthPluginObject;
/// set to TRUE when we press the 'Skip' button
static bool isSkip = FALSE;
/// PIN input graphical widget.
/**
* Inherits the PinDialogBase class defined originally in pinDialogBase.ui interface file.
* \sa PinDlg and PinDialog (the class generated from the .ui file)
* It comes from the original PIN locking code in Opie :
* \sa http://dudu.dyn.2-h.org/opiedoxydoc/library_2password_8cpp-source.html
*/
class PinDialog : public PinDialogBase
{
Q_OBJECT
public:
PinDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~PinDialog();
void clear();
void setPrompt( const QString& );
signals:
/// emitted when we press the Enter button
void passwordEntered( const QString& );
/// emitted when we press the Skip button
void skip();
protected:
bool eventFilter( QObject*, QEvent* );
private:
void input( QString );
friend class PinPlugin;
QString text;
};
/// Constructs a PinDialog widget, and initializes things
PinDialog::PinDialog( QWidget* parent, const char* name, WFlags fl )
: PinDialogBase( parent, name, fl )
{
QRect desk = oApp->desktop()->geometry();
if ( desk.width() < 220 ) {
@@ -257,89 +256,100 @@ QString PinPlugin::getPIN( const QString& prompt )
QString PinPlugin::getCryptedPIN( const QString& prompt )
{
return encrypt(getPIN(prompt));
}
/// Displays the PIN dialog, asks 2 times for a new PIN, saves it if entered two times
/**
* writes nothing if we enter nothing the first time
*/
void PinPlugin::changePIN()
{
QString new1, new2;
do {
new1 = getPIN(QObject::tr("Enter new PIN"));
if ( new1.isNull() )
return;
new2 = getPIN(QObject::tr("Re-enter new PIN"));
} while (new1 != new2);
odebug << "writing new PIN hash in Security.conf" << oendl;
Config cfg("Security");
cfg.setGroup("PinPlugin");
cfg.writeEntry("hashedPIN", encrypt(new1));
}
/// Removes the PIN hashed value in the config file
void PinPlugin::clearPIN()
{
Config cfg("Security");
cfg.setGroup("PinPlugin");
cfg.removeEntry("hashedPIN");
}
/// Prompt, fullscreen, for the user's PIN and compare it to the stored one.
/**
* \return the result code, as a MultiauthPluginObject::authResult object
*/
int PinPlugin::authenticate()
{
// reset skip (if we ran Pin two times in a row, skipping the first time, it must be put to 0 again)
isSkip = FALSE;
// fetch value in config
Config cfg("Security");
cfg.setGroup("PinPlugin");
QString hashedPin = cfg.readEntry("hashedPIN");
if (!hashedPin.isEmpty())
{
// prompt for the PIN in a fullscreen modal dialog
PinDlg pd(0,0,TRUE,TRUE);
pd.reset();
pd.exec();
// analyse the result
if (isSkip == TRUE)
return MultiauthPluginObject::Skip;
else if (verify(pd.pinD->text, hashedPin))
return MultiauthPluginObject::Success;
else
return MultiauthPluginObject::Failure;
}
owarn << "No PIN has been defined! We consider it as a successful authentication though." << oendl;
return MultiauthPluginObject::Success;
}
+/// Standard c'tor
+PinPlugin::PinPlugin() : MultiauthPluginObject(), m_pinW(0) {
+}
+
+/// deletes m_pinW if we need to
+PinPlugin::~PinPlugin() {
+ if (m_pinW != 0)
+ delete m_pinW;
+}
+
/// Simply returns the plugin name (PIN plugin)
QString PinPlugin::pluginName() const {
return "PIN Plugin";
}
QString PinPlugin::pixmapNameWidget() const {
return "security/pinplugin";
}
QString PinPlugin::pixmapNameConfig() const {
return "security/pinplugin";
}
/// returns a PinConfigWidget
MultiauthConfigWidget * PinPlugin::configWidget(QWidget * parent) {
- PinConfigWidget * pinw = new PinConfigWidget(parent, "PIN configuration widget");
-
- connect(pinw->changePIN, SIGNAL( clicked() ), this, SLOT( changePIN() ));
- connect(pinw->clearPIN, SIGNAL( clicked() ), this, SLOT( clearPIN() ));
+ if (m_pinW == 0) {
+ m_pinW = new PinConfigWidget(parent, "PIN configuration widget");
- return pinw;
+ connect(m_pinW->changePIN, SIGNAL( clicked() ), this, SLOT( changePIN() ));
+ connect(m_pinW->clearPIN, SIGNAL( clicked() ), this, SLOT( clearPIN() ));
+ }
+ return m_pinW;
}
#include "pin.moc"
diff --git a/noncore/securityplugins/pin/pin.h b/noncore/securityplugins/pin/pin.h
index 1832210..b5ae10a 100644
--- a/noncore/securityplugins/pin/pin.h
+++ b/noncore/securityplugins/pin/pin.h
@@ -1,68 +1,71 @@
/**
* \file pin.h
* \brief Standard Opie multiauth plugin definition
* \author Clément Séveillac (clement . seveillac (at) via . ecp . fr)
*/
/*
=. This file is part of the Opie Project
.=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
.>+-=
_;:, .> :=|. This library is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This library is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef PIN_H
#define PIN_H
#include <qobject.h>
#include <qstring.h>
#include <opie2/multiauthplugininterface.h>
#include "pinConfigWidget.h"
/// Multi-authentication plugin, implementing a PIN verification.
/**
* The plugin itself, implementing the main authenticate() function.
*/
class PinPlugin : public QObject, public Opie::Security::MultiauthPluginObject {
Q_OBJECT
public:
+ PinPlugin();
+ virtual ~PinPlugin();
int authenticate();
Opie::Security::MultiauthConfigWidget * configWidget(QWidget * parent);
QString pixmapNameConfig() const;
QString pixmapNameWidget() const;
QString pluginName() const;
private slots:
QString getPIN( const QString& prompt );
QString getCryptedPIN( const QString& prompt );
void changePIN();
void clearPIN();
private:
+ PinConfigWidget * m_pinW;
QString encrypt(const QString& pin);
bool verify(const QString& pin, const QString& hash);
};
#endif // PIN_H