From e1e38b0f90748fc44eb7325c2be136c702b8d2c2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 19 Feb 2023 00:26:46 -0800 Subject: [PATCH] Hook up password storing for Linux client --- Sources/Plasma/Apps/plClient/linux/main.cpp | 35 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/linux/main.cpp b/Sources/Plasma/Apps/plClient/linux/main.cpp index d2e5140c41..b13dacf847 100644 --- a/Sources/Plasma/Apps/plClient/linux/main.cpp +++ b/Sources/Plasma/Apps/plClient/linux/main.cpp @@ -77,6 +77,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plStatusLog/plStatusLog.h" #include "pfConsoleCore/pfConsoleEngine.h" +#include "pfPasswordStore/pfPasswordStore.h" extern bool gDataServerLocal; extern bool gSkipPreload; @@ -276,16 +277,42 @@ static bool ConsoleLoginScreen() fflush(stdout); char username[kMaxAccountNameLength]; - char password[kMaxPasswordLength]; if (fscanf(stdin, "%s", username) != 1) { return false; } - fprintf(stdout, "Password: "); - fflush(stdout); + pfPasswordStore* store = pfPasswordStore::Instance(); + ST::string password = store->GetPassword(username); + + if (!password.empty()) { + fprintf(stdout, "Use saved password? [y/n] "); + fflush(stdout); + char c; + fscanf(stdin, " %c", &c); + if (c == 'n' || c == 'N') { + password = ST_LITERAL(""); + } + fprintf(stdout, "\n"); + } - getpassword(password); + if (password.empty()) { + fprintf(stdout, "Password: "); + fflush(stdout); + + char tmpPassword[kMaxPasswordLength]; + getpassword(tmpPassword); + password = tmpPassword; + + fprintf(stdout, "Save password? [y/n] "); + fflush(stdout); + char c; + fscanf(stdin, " %c", &c); + if (c == 'y' || c == 'Y') { + store->SetPassword(username, password); + } + fprintf(stdout, "\n"); + } ShaDigest namePassHash; CalculateHash(username, password, namePassHash);