mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
LibCore: Make get_salt() fallible so we get an error instead of crashing
This commit is contained in:
1 parent
61ebfdab56
commit
2f3ad5ca28
3 files changed
+7
-7
No files matched your search
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
static ByteString get_salt()
|
static ErrorOr<ByteString> get_salt()
|
||||||
{
|
{
|
||||||
char random_data[12];
|
char random_data[12];
|
||||||
fill_with_random({ random_data, sizeof(random_data) });
|
fill_with_random({ random_data, sizeof(random_data) });
|
||||||
@@ -35,8 +35,7 @@ static ByteString get_salt()
|
|||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append("$5$"sv);
|
builder.append("$5$"sv);
|
||||||
|
|
||||||
// FIXME: change to TRY() and make method fallible
|
auto salt_string = TRY(encode_base64({ random_data, sizeof(random_data) }));
|
||||||
auto salt_string = MUST(encode_base64({ random_data, sizeof(random_data) }));
|
|
||||||
builder.append(salt_string);
|
builder.append(salt_string);
|
||||||
|
|
||||||
return builder.to_byte_string();
|
return builder.to_byte_string();
|
||||||
@@ -184,9 +183,10 @@ ErrorOr<void> Account::login() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Account::set_password(SecretString const& password)
|
ErrorOr<void> Account::set_password(SecretString const& password)
|
||||||
{
|
{
|
||||||
m_password_hash = crypt(password.characters(), get_salt().characters());
|
m_password_hash = crypt(password.characters(), TRY(get_salt()).characters());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Account::set_password_enabled(bool enabled)
|
void Account::set_password_enabled(bool enabled)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
|
|
||||||
// Setters only affect in-memory copy of password.
|
// Setters only affect in-memory copy of password.
|
||||||
// You must call sync to apply changes.
|
// You must call sync to apply changes.
|
||||||
void set_password(SecretString const& password);
|
ErrorOr<void> set_password(SecretString const& password);
|
||||||
void set_password_enabled(bool enabled);
|
void set_password_enabled(bool enabled);
|
||||||
void set_home_directory(StringView home_directory) { m_home_directory = home_directory; }
|
void set_home_directory(StringView home_directory) { m_home_directory = home_directory; }
|
||||||
void set_uid(uid_t uid) { m_uid = uid; }
|
void set_uid(uid_t uid) { m_uid = uid; }
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
target_account.set_password(new_password);
|
TRY(target_account.set_password(new_password));
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(Core::System::pledge("stdio wpath rpath cpath fattr"));
|
TRY(Core::System::pledge("stdio wpath rpath cpath fattr"));
|
||||||
|
|||||||
Reference in new issue
Block a user