4
4
5
5
#include " server/acl/user.h"
6
6
7
- #include < xxhash .h>
7
+ #include < openssl/sha .h>
8
8
9
9
namespace dfly {
10
10
11
+ namespace {
12
+ std::string StringSHA256 (std::string_view password) {
13
+ std::string hash;
14
+ hash.resize (SHA256_DIGEST_LENGTH);
15
+ SHA256 (reinterpret_cast <const unsigned char *>(password.data ()), password.size (),
16
+ reinterpret_cast <unsigned char *>(hash.data ()));
17
+ return hash;
18
+ }
19
+
20
+ } // namespace
21
+
11
22
User::User () {
12
23
// acl_categories_ = AclCat::ACL_CATEGORY_ADMIN;
13
24
}
14
25
15
26
void User::Update (UpdateRequest&& req) {
16
27
if (req.password ) {
17
- SetPassword (*req.password );
28
+ SetPasswordHash (*req.password );
18
29
}
19
30
20
31
if (req.plus_acl_categories ) {
@@ -30,19 +41,19 @@ void User::Update(UpdateRequest&& req) {
30
41
}
31
42
}
32
43
33
- void User::SetPassword (std::string_view password) {
34
- password_ = HashPassword (password);
44
+ void User::SetPasswordHash (std::string_view password) {
45
+ password_hash_ = StringSHA256 (password);
35
46
}
36
47
37
48
bool User::HasPassword (std::string_view password) const {
38
- if (!password_ ) {
49
+ if (!password_hash_ ) {
39
50
if (password == " nopass" ) {
40
51
return true ;
41
52
}
42
53
return false ;
43
54
}
44
55
// hash password and compare
45
- return *password_ == HashPassword (password);
56
+ return *password_hash_ == StringSHA256 (password);
46
57
}
47
58
48
59
void User::SetAclCategories (uint64_t cat) {
@@ -70,8 +81,4 @@ bool User::IsActive() const {
70
81
return is_active_;
71
82
}
72
83
73
- uint32_t User::HashPassword (std::string_view password) const {
74
- return XXH3_64bits (password.data (), password.size ());
75
- }
76
-
77
84
} // namespace dfly
0 commit comments