Cutelyst  1.5.0
credentialpassword.h
1 /*
2  * Copyright (C) 2013-2014 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
21 #define CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
22 
23 #include <QtCore/QCryptographicHash>
24 
25 #include <Cutelyst/cutelyst_global.h>
26 #include <Cutelyst/Plugins/Authentication/authentication.h>
27 
28 namespace Cutelyst {
29 
30 class CredentialPasswordPrivate;
31 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT CredentialPassword : public AuthenticationCredential
32 {
33  Q_OBJECT
34  Q_DECLARE_PRIVATE(CredentialPassword)
35 public:
36  enum Type {
37  None,
38  Clear,
39  Hashed,
40  SelfCheck
41  };
42  Q_ENUM(Type)
43  explicit CredentialPassword(QObject *parent = nullptr);
44  virtual ~CredentialPassword();
45 
46  AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) final;
47 
48  QString passwordField() const;
49  void setPasswordField(const QString &fieldName);
50 
51  Type passwordType() const;
52  void setPasswordType(Type type);
53 
54  QString passwordPreSalt() const;
55  void setPasswordPreSalt(const QString &passwordPreSalt);
56 
57  QString passwordPostSalt() const;
58  void setPasswordPostSalt(const QString &passwordPostSalt);
59 
60  static bool validatePassword(const QByteArray &password, const QByteArray &correctHash);
61  static QByteArray createPassword(const QByteArray &password, QCryptographicHash::Algorithm method, int iterations, int saltByteSize, int hashByteSize);
62  static QByteArray pbkdf2(QCryptographicHash::Algorithm method,
63  const QByteArray &password, const QByteArray &salt,
64  int rounds, int keyLength);
65  QByteArray hmac(QCryptographicHash::Algorithm method, QByteArray key, const QByteArray& message);
66 
67 protected:
68  CredentialPasswordPrivate *d_ptr;
69 };
70 
71 } // namespace Plugin
72 
73 #endif // CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst Context.
Definition: context.h:52
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7