1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVL_PASSWORDHELPER_HXX
21 #define INCLUDED_SVL_PASSWORDHELPER_HXX
23 #include <sal/config.h>
25 #include <string_view>
28 #include <svl/svldllapi.h>
29 #include <sal/types.h>
30 #include <com/sun/star/uno/Sequence.hxx>
32 class SvPasswordHelper
34 static void GetHashPasswordLittleEndian(css::uno::Sequence
<sal_Int8
>& rPassHash
, std::u16string_view sPass
);
35 static void GetHashPasswordBigEndian(css::uno::Sequence
<sal_Int8
>& rPassHash
, std::u16string_view sPass
);
38 SVL_DLLPUBLIC
static void GetHashPassword(css::uno::Sequence
<sal_Int8
>& rPassHash
, const char* pPass
, sal_uInt32 nLen
);
40 SVL_DLLPUBLIC
static void GetHashPassword(css::uno::Sequence
<sal_Int8
>& rPassHash
, std::u16string_view sPass
);
41 SVL_DLLPUBLIC
static void GetHashPasswordSHA1UTF8(css::uno::Sequence
<sal_Int8
>& rPassHash
, std::u16string_view sPass
);
42 SVL_DLLPUBLIC
static void GetHashPasswordSHA256(css::uno::Sequence
<sal_Int8
>& rPassHash
, std::u16string_view sPass
);
44 Use this method to compare a given string with another given Hash value.
45 This is necessary, because in older versions exists different hashes of the same string. They were endian dependent.
46 We need this to handle old files. This method will compare against big and
48 tdf#115483: also check 2 different new ways of hashing that were added in
49 ODF 1.2, requiring UTF-8 encoding.
51 SVL_DLLPUBLIC
static bool CompareHashPassword(const css::uno::Sequence
<sal_Int8
>& rOldPassHash
, std::u16string_view sNewPass
);
53 /** Get password strength percentage
55 Maps the calculated password entropy bit amount to password strength percentage:
59 @param pPassword null terminated password string.
60 @returns Password strength percentage in the range [0.0, 100.0]
62 SVL_DLLPUBLIC
static double GetPasswordStrengthPercentage(const char* pPassword
);
63 SVL_DLLPUBLIC
static double GetPasswordStrengthPercentage(const OUString
& aPassword
);
65 /** Checks if the password meets the password policies
67 @param pPassword null terminated password string.
68 @param oPasswordPolicy Regular expression string that defines the password policy.
70 @returns true if password meets the policy or there is no policy enforced.
72 SVL_DLLPUBLIC
static bool PasswordMeetsPolicy(const char* pPassword
,
73 const std::optional
<OUString
>& oPasswordPolicy
);
74 SVL_DLLPUBLIC
static bool PasswordMeetsPolicy(const OUString
& aPassword
,
75 const std::optional
<OUString
>& oPasswordPolicy
);
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */