Cutelyst
2.14.2
Cutelyst
Plugins
Authentication
credentialpassword.h
1
/*
2
* Copyright (C) 2013-2017 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 Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 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
* Lesser General Public License for more details.
13
*
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
#ifndef CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
19
#define CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
20
21
#include <QtCore/QCryptographicHash>
22
23
#include <Cutelyst/cutelyst_global.h>
24
#include <Cutelyst/Plugins/Authentication/authentication.h>
25
26
namespace
Cutelyst
{
27
28
class
CredentialPasswordPrivate;
29
class
CUTELYST_PLUGIN_AUTHENTICATION_EXPORT
CredentialPassword
:
public
AuthenticationCredential
30
{
31
Q_OBJECT
32
Q_DECLARE_PRIVATE(
CredentialPassword
)
33
public
:
34
enum
PasswordType {
35
None,
36
Clear,
37
Hashed
38
};
39
Q_ENUM(PasswordType)
40
41
44
explicit
CredentialPassword
(
QObject
*parent =
nullptr
);
45
virtual
~
CredentialPassword
()
override
;
46
47
AuthenticationUser
authenticate(
Context
*c,
AuthenticationRealm
*realm,
const
ParamsMultiMap
&authinfo)
final
;
48
52
QString
passwordField()
const
;
53
57
void
setPasswordField(
const
QString
&fieldName);
58
62
PasswordType passwordType()
const
;
63
67
void
setPasswordType(PasswordType type);
68
72
QString
passwordPreSalt()
const
;
73
77
void
setPasswordPreSalt(
const
QString
&passwordPreSalt);
78
82
QString
passwordPostSalt()
const
;
83
87
void
setPasswordPostSalt(
const
QString
&passwordPostSalt);
88
92
static
bool
validatePassword(
const
QByteArray
&password,
const
QByteArray
&correctHash);
93
104
static
QByteArray
createPassword(
const
QByteArray
&password,
QCryptographicHash::Algorithm
method,
int
iterations,
int
saltByteSize,
int
hashByteSize);
105
112
static
QByteArray
createPassword(
const
QByteArray
&password);
113
120
inline
static
QByteArray
createPassword(
const
QString
&password);
121
131
static
QByteArray
pbkdf2(
QCryptographicHash::Algorithm
method,
132
const
QByteArray
&password,
const
QByteArray
&salt,
133
int
rounds,
int
keyLength);
134
138
static
QByteArray
hmac(
QCryptographicHash::Algorithm
method,
const
QByteArray
&key,
const
QByteArray
&message);
139
140
protected
:
141
CredentialPasswordPrivate *d_ptr;
142
};
143
144
QByteArray
CredentialPassword::createPassword
(
const
QString
&password)
145
{
146
return
createPassword
(password.
toUtf8
());
147
}
148
149
}
// namespace Plugin
150
151
#endif // CUTELYSTPLUGIN_CREDENTIALPASSWORD_H
Cutelyst::AuthenticationCredential
Definition:
authentication.h:32
Cutelyst::Context
The Cutelyst Context.
Definition:
context.h:52
Cutelyst::AuthenticationUser
Definition:
authenticationuser.h:32
QObject
QString
QString::toUtf8
QByteArray toUtf8() const const
Cutelyst::CredentialPassword::createPassword
static QByteArray createPassword(const QByteArray &password, QCryptographicHash::Algorithm method, int iterations, int saltByteSize, int hashByteSize)
Creates a password hash string.
Definition:
credentialpassword.cpp:146
Cutelyst::AuthenticationRealm
Definition:
authenticationrealm.h:31
QMap
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition:
Mainpage.dox:8
QByteArray
QCryptographicHash::Algorithm
Algorithm
Cutelyst::CredentialPassword
Definition:
credentialpassword.h:30
Generated by
1.8.20