Cutelyst  1.8.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 
44 
47  explicit CredentialPassword(QObject *parent = nullptr);
48  virtual ~CredentialPassword();
49 
50  AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) final;
51 
55  QString passwordField() const;
56 
60  void setPasswordField(const QString &fieldName);
61 
65  Type passwordType() const;
66 
70  void setPasswordType(Type type);
71 
75  QString passwordPreSalt() const;
76 
80  void setPasswordPreSalt(const QString &passwordPreSalt);
81 
85  QString passwordPostSalt() const;
86 
90  void setPasswordPostSalt(const QString &passwordPostSalt);
91 
95  static bool validatePassword(const QByteArray &password, const QByteArray &correctHash);
96 
106  static QByteArray createPassword(const QByteArray &password, QCryptographicHash::Algorithm method, int iterations, int saltByteSize, int hashByteSize);
107 
117  static QByteArray pbkdf2(QCryptographicHash::Algorithm method,
118  const QByteArray &password, const QByteArray &salt,
119  int rounds, int keyLength);
120 
124  QByteArray hmac(QCryptographicHash::Algorithm method, QByteArray key, const QByteArray& message);
125 
126 protected:
127  CredentialPasswordPrivate *d_ptr;
128 };
129 
130 } // namespace Plugin
131 
132 #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