0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️ Add m::user helpers to generate password hash and access tokens.

This commit is contained in:
Jason Volk 2018-02-15 13:05:00 -08:00
parent 51b2cafc74
commit 050eacd142
2 changed files with 30 additions and 0 deletions

View file

@ -25,6 +25,9 @@ struct ircd::m::user
static room accounts;
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_password(const string_view &password) const;

View file

@ -201,3 +201,30 @@ const
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);
}