summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
Diffstat (limited to 'clients')
-rw-r--r--clients/screens_dashboard.c66
-rw-r--r--clients/tui.c2
2 files changed, 68 insertions, 0 deletions
diff --git a/clients/screens_dashboard.c b/clients/screens_dashboard.c
index 127d4df..45f0aed 100644
--- a/clients/screens_dashboard.c
+++ b/clients/screens_dashboard.c
@@ -275,9 +275,72 @@ static const char *const MAIN_ITEMS[] = {
"Bolaget", "System",
"Ingående balans", "Räkenskapsår",
"Byt bolag",
+ "Byt lösenord",
"Logga ut / avsluta",
};
+#define PASSWORD_MIN_LEN 10 /* user.set_password's server-side minimum */
+
+/* Changes the logged-in user's password (user.set_password). Every prompt
+ is masked; Esc anywhere cancels without a request. */
+static void change_password(struct app *a)
+{
+ char cur[128] = "", pw[128] = "", again[128] = "";
+ if (!tui_prompt_into(cur, sizeof cur, "Nuvarande lösenord: ", "", 1) ||
+ !tui_prompt_into(pw, sizeof pw, "Nytt lösenord (minst 10 tecken): ",
+ "", 1) ||
+ !tui_prompt_into(again, sizeof again, "Upprepa nytt lösenord: ", "",
+ 1))
+ goto done;
+ if (strlen(pw) < PASSWORD_MIN_LEN) {
+ tui_message("Byt lösenord",
+ "Det nya lösenordet måste ha minst %d tecken.",
+ PASSWORD_MIN_LEN);
+ goto done;
+ }
+ if (strcmp(pw, again) != 0) {
+ tui_message("Byt lösenord", "Lösenorden stämmer inte överens.");
+ goto done;
+ }
+ if (strcmp(pw, cur) == 0) {
+ tui_message("Byt lösenord",
+ "Det nya lösenordet måste skilja sig från det nuvarande.");
+ goto done;
+ }
+ yyjson_mut_doc *d = yyjson_mut_doc_new(NULL);
+ yyjson_mut_val *o = yyjson_mut_obj(d);
+ yyjson_mut_doc_set_root(d, o);
+ yyjson_mut_obj_add_strcpy(d, o, "current_password", cur);
+ yyjson_mut_obj_add_strcpy(d, o, "new_password", pw);
+ char *args = yyjson_mut_write(d, 0, NULL);
+ yyjson_mut_doc_free(d);
+ char *resp = client_rpc(&a->conn, "user.set_password", a->session, 0,
+ args);
+ if (args) {
+ memset(args, 0, strlen(args));
+ free(args);
+ }
+ if (resp && client_ok(resp)) {
+ int64_t closed = jint_val(resp, "result.sessions_closed", 0);
+ /* ^R re-logs in with the kept password */
+ if (a->password[0])
+ snprintf(a->password, sizeof a->password, "%s", pw);
+ tui_message("Byt lösenord",
+ "Lösenordet är bytt.%s\n"
+ "Loggar du in via bokftui-bw: uppdatera lösenordet i "
+ "Bitwarden.",
+ closed > 0 ? " Dina andra inloggningar har loggats ut."
+ : "");
+ } else {
+ show_error("Byt lösenord", resp);
+ }
+ free(resp);
+done:
+ memset(cur, 0, sizeof cur);
+ memset(pw, 0, sizeof pw);
+ memset(again, 0, sizeof again);
+}
+
/* Picks another org and reloads everything that belongs to the org: its
context (name, role, current fiscal year, series) and the remembered
list selections. */
@@ -356,6 +419,9 @@ void dashboard(struct app *a)
switch_org(a);
break;
case 13:
+ change_password(a);
+ break;
+ case 14:
return;
default:
break;
diff --git a/clients/tui.c b/clients/tui.c
index 4bc1d66..43a3d27 100644
--- a/clients/tui.c
+++ b/clients/tui.c
@@ -596,6 +596,8 @@ static int field_scratch(int y, int x, int width, char *buf, size_t cap,
int rc = field_loop(y, x, width, scratch, cap, mask, date, tabs, 1, first);
if (rc)
snprintf(buf, cap, "%s", scratch);
+ if (mask)
+ memset(scratch, 0, cap); /* no password copy left in freed memory */
free(scratch);
return rc;
}