diff --git a/Userland/Libraries/LibCore/GetPassword.cpp b/Userland/Libraries/LibCore/GetPassword.cpp index 252f5dce74..ea454a6058 100644 --- a/Userland/Libraries/LibCore/GetPassword.cpp +++ b/Userland/Libraries/LibCore/GetPassword.cpp @@ -13,7 +13,7 @@ namespace Core { -Result get_password(const StringView& prompt) +Result get_password(const StringView& prompt) { if (write(STDOUT_FILENO, prompt.characters_without_null_termination(), prompt.length()) < 0) return OSError(errno); @@ -44,8 +44,6 @@ Result get_password(const StringView& prompt) // Remove trailing '\n' read by getline(). password[line_length - 1] = '\0'; - String s(password); - free(password); - return s; + return SecretString::take_ownership(password, line_length); } } diff --git a/Userland/Libraries/LibCore/GetPassword.h b/Userland/Libraries/LibCore/GetPassword.h index ed16fd74bc..6e1e17ed26 100644 --- a/Userland/Libraries/LibCore/GetPassword.h +++ b/Userland/Libraries/LibCore/GetPassword.h @@ -9,9 +9,10 @@ #include #include #include +#include namespace Core { -Result get_password(const StringView& prompt = "Password: "); +Result get_password(const StringView& prompt = "Password: "sv); } diff --git a/Userland/Utilities/passwd.cpp b/Userland/Utilities/passwd.cpp index 23a8c1c242..70860db604 100644 --- a/Userland/Utilities/passwd.cpp +++ b/Userland/Utilities/passwd.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -114,7 +115,7 @@ int main(int argc, char** argv) return 1; } - if (new_password.value() != new_password_retype.value()) { + if (new_password.value().view() != new_password_retype.value().view()) { warnln("Sorry, passwords don't match."); warnln("Password for user {} unchanged.", target_account.username()); return 1; diff --git a/Userland/Utilities/pls.cpp b/Userland/Utilities/pls.cpp index a54e76711a..e617e7d8a0 100644 --- a/Userland/Utilities/pls.cpp +++ b/Userland/Utilities/pls.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Userland/Utilities/su.cpp b/Userland/Utilities/su.cpp index 9e4827dad6..c9290fd63c 100644 --- a/Userland/Utilities/su.cpp +++ b/Userland/Utilities/su.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include diff --git a/Userland/Utilities/test-imap.cpp b/Userland/Utilities/test-imap.cpp index bcafc04532..15339f030a 100644 --- a/Userland/Utilities/test-imap.cpp +++ b/Userland/Utilities/test-imap.cpp @@ -22,7 +22,7 @@ int main(int argc, char** argv) bool tls { false }; String username; - String password; + Core::SecretString password; bool interactive_password; @@ -40,17 +40,17 @@ int main(int argc, char** argv) warnln("{}", password_or_err.error().string()); return 1; } - password = password_or_err.value(); + password = password_or_err.release_value(); } else { auto standard_input = Core::File::standard_input(); - password = standard_input->read_all(); + password = Core::SecretString::take_ownership(standard_input->read_all()); } Core::EventLoop loop; auto client = IMAP::Client(host, port, tls); client.connect()->await(); - auto response = client.login(username, password)->await().release_value(); + auto response = client.login(username, password.view())->await().release_value(); outln("[LOGIN] Login response: {}", response.response_text()); response = move(client.send_simple_command(IMAP::CommandType::Capability)->await().value().get());