mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd:Ⓜ️ Add m::user helpers to generate password hash and access tokens.
This commit is contained in:
parent
51b2cafc74
commit
050eacd142
2 changed files with 30 additions and 0 deletions
|
@ -25,6 +25,9 @@ struct ircd::m::user
|
||||||
static room accounts;
|
static room accounts;
|
||||||
static room sessions;
|
static room sessions;
|
||||||
|
|
||||||
|
static string_view gen_password_hash(const mutable_buffer &out, const string_view &candidate);
|
||||||
|
static string_view gen_access_token(const mutable_buffer &out);
|
||||||
|
|
||||||
bool is_active() const;
|
bool is_active() const;
|
||||||
bool is_password(const string_view &password) const;
|
bool is_password(const string_view &password) const;
|
||||||
|
|
||||||
|
|
|
@ -201,3 +201,30 @@ const
|
||||||
buf, user_id.local(), my_host()
|
buf, user_id.local(), my_host()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ircd::string_view
|
||||||
|
ircd::m::user::gen_access_token(const mutable_buffer &buf)
|
||||||
|
{
|
||||||
|
static const size_t token_max{32};
|
||||||
|
static const auto &token_dict{rand::dict::alpha};
|
||||||
|
|
||||||
|
const mutable_buffer out
|
||||||
|
{
|
||||||
|
data(buf), std::min(token_max, size(buf))
|
||||||
|
};
|
||||||
|
|
||||||
|
return rand::string(token_dict, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::string_view
|
||||||
|
ircd::m::user::gen_password_hash(const mutable_buffer &out,
|
||||||
|
const string_view &supplied_password)
|
||||||
|
{
|
||||||
|
//TODO: ADD SALT
|
||||||
|
const sha256::buf hash
|
||||||
|
{
|
||||||
|
sha256{supplied_password}
|
||||||
|
};
|
||||||
|
|
||||||
|
return b64encode_unpadded(out, hash);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue